我已经设计我的机器人2-3周了。我已经使不一致机器人DM命令,我可以发送消息给任何人谁是我们的服务器的成员..而是如何阅读他们对机器人的回复
发布于 2020-01-13 01:25:21
使用"message“事件,在DM中获取消息的方式与获取普通消息的方式相同。要查看邮件是否在DM中发送,请检查message.guild是否存在。例如:
if (!message.guild) {return console.log(`New Message in DMs: ${message.content}`)}
根据你的评论,"i want to see that message in a specific channel and with their names
",你必须检查Channel ID。您可以使用Message's Author属性获取消息作者的姓名。
下面是一个例子:
const Discord = require("discord.js");
const Client = new Discord.Client();
Client.on("message", (message) => {
if (message.author.bot) return false; // If the message is sent by a bot, we ignore it.
if (message.channel.id == "661567766444376085") { // Checking if the message is sent in a certain channel.
let Channel = message.client.channels.get("661567766444376085"); // Getting the channel object.
console.log(`New message in #${Channel.name} from ${message.author.tag}: ${message.content}`);
};
});
Client.login("TOKEN");
输出应该是:New message in #channel_name from Author#0000: Message Content!
。
发布于 2020-01-13 15:21:00
不一致不具备作为对话与用户交流的内置功能。为了组织这样的交流,有几种选择。您可以使用channel.fetchMessages
方法,该方法将对话框中的所有消息作为集合返回,但这不是很方便。您可以创建一个服务器,并在此服务器中为每个用户创建一个通道,并在那里发送他的消息,并在dm中将您的消息发送给他。有许多实现选项,但所有这些选项都需要认真研究才能正确工作。
发布于 2020-01-13 00:28:02
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') { //read messages
msg.reply('pong');
}
});
client.login('token');
对于官方文档,请单击here。
https://stackoverflow.com/questions/59705472
复制相似问题