首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我们如何读取某个用户发送给我们的机器人的消息?

我们如何读取某个用户发送给我们的机器人的消息?
EN

Stack Overflow用户
提问于 2020-01-12 23:46:43
回答 3查看 2.3K关注 0票数 1

我已经设计我的机器人2-3周了。我已经使不一致机器人DM命令,我可以发送消息给任何人谁是我们的服务器的成员..而是如何阅读他们对机器人的回复

EN

Stack Overflow用户

回答已采纳

发布于 2020-01-13 01:25:21

使用"message“事件,在DM中获取消息的方式与获取普通消息的方式相同。要查看邮件是否在DM中发送,请检查message.guild是否存在。例如:

代码语言:javascript
运行
复制
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属性获取消息作者的姓名。

下面是一个例子:

代码语言:javascript
运行
复制
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!

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59705472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档