Discord JS检测其他机器人的消息

时间:2020-09-04 11:37:57

标签: javascript node.js discord discord.js

我正在尝试检测来自另一个不和谐机器人的消息。例如,如果另一个不和谐的bot说出“ captcha”一词,我的不和谐的bot将检测到它并ping通我。希望有一种方法也可以检测到另一个僵尸程序的嵌入,而不仅仅是消息。

2 个答案:

答案 0 :(得分:1)

您可以使用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]`
 }
});

答案 1 :(得分:0)

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

如果发送消息的人是机器人,则

message.author.bot将返回true,否则返回false

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