我已经设计我的机器人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!
。
https://stackoverflow.com/questions/59705472
复制相似问题