我一直在设计我的机器人2-3周。我已经通过发出Discord bot DM命令,可以将消息发送给我们服务器成员的任何人..但是如何读取他们对该机器人的答复
最佳答案
使用“ 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!
。