Nathaniel Jorge
Nathaniel Jorge

Reputation: 3

Discord js detect other bot's message

I'm trying to detect a message that comes from another discord bot. Like for example, if the other discord bot says the word "captcha", my discord bot will detect it and ping me. Hopefully, there's also a way to detect another bot's embed too, not only messages.

Upvotes: 0

Views: 1890

Answers (2)

Lioness100
Lioness100

Reputation: 8412

You can detect if a user is a bot using the bot property on a 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]`
 }
});

Upvotes: 1

Elitezen
Elitezen

Reputation: 6710

You can get the bot property from author (user object)

message.author.bot will return true if whoever sent the message is a bot, otherwise false.

For your "captcha" detection you would just need to check message.content

Upvotes: 0

Related Questions