【问题标题】:Discord js detect other bot's messageDiscord js检测其他机器人的消息
【发布时间】:2020-12-23 16:24:32
【问题描述】:

我正在尝试检测来自另一个不和谐机器人的消息。例如,如果另一个不和谐机器人说出“验证码”这个词,我的不和谐机器人会检测到它并 ping 我。希望还有一种方法可以检测另一个机器人的嵌入,而不仅仅是消息。

【问题讨论】:

  • 嗨,如果用户是像 message.author.bot 这样的机器人,我猜每条消息都有一个包含标志的用户属性

标签: javascript node.js discord discord.js


【解决方案1】:

您可以使用User 上的bot 属性检测用户是否是机器人。

// create a message event
client.on('message', (message) => {
 if (message.author.bot) {
  // if the message is a bot
  console.log(`${message.author.username} sent: '${message.content}'`); // you can fetch the message text through `message.content`

  if (message.embeds[0])
   // if the message includes an embed
   console.log(
    `${message.author.username} sent an embed with the title ${message.embeds[0].title}`
   ); // you can fetch the embed content through `message.embeds[0]`
 }
});

【讨论】:

  • 像我想要的那样工作!现在剩下的唯一问题是我得到了我需要的嵌入内容,它位于页脚。我想提出一个条件,即如果提取的嵌入中包含特定单词,我将对嵌入本身做出反应。顺便谢谢你的帮助^^
  • 你可以试试:if (message.embeds[0].footer.includes('specific word')) message.react(reaction)
  • 上面写着Cannot read property footer of undefined。我尝试调整您发送给我的代码,但无济于事。
  • 这只是意味着您调用它的特定消息没有嵌入
  • 感谢您仍然发送的代码并在for (var i = 0; i < message.embeds.length; i++) { if (message.embeds[i] && message.embeds[i].footer && message.embeds[i].footer.text.includes('left')) { message.react('?') 周围询问了一些问题,找到了问题的解决方案并完成了任务。非常感谢大家的帮助^^
【解决方案2】:

您可以从author(用户对象)获取bot 属性

如果发送消息的人是机器人,message.author.bot 将返回 true,否则返回 false

对于您的“验证码”检测,您只需检查message.content

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2017-11-01
    • 2018-09-14
    • 2019-04-24
    • 2020-08-24
    • 2020-07-04
    • 1970-01-01
    • 2019-12-23
    • 2021-08-19
    相关资源
    最近更新 更多