首页 > 解决方案 > Discord js检测其他机器人的消息

问题描述

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

标签: javascriptnode.jsdiscorddiscord.js

解决方案


您可以使用bot.User

// 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]`
 }
});

推荐阅读