我已经设计我的机器人 2-3 周了。我已经通过discord bot DM命令我可以向我们服务器的任何成员发送消息..但是如何阅读他们回复该机器人的内容
最佳答案
使用“message”事件,您可以像获取普通消息一样在私信中获取消息。 要查看消息是否通过 DM 发送,请检查 message.guild 是否存在。 例如:
if (!message.guild) {return console.log(`New Message in DMs: ${message.content}`)}
根据您的评论,“我想在特定 channel 中查看该消息及其名称
”,您必须检查 Channel ID 。您可以使用 Message's 获取消息作者姓名Author属性(property)。
这是一个例子:
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");
输出应为:来自 Author#0000 的 #channel_name 中的新消息:消息内容!
。
关于javascript - 我们如何阅读某些用户发送给我们的机器人的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59705472/