meow-meow-meow
meow-meow-meow

Reputation: 518

How do I get a discord bot to add a reaction to its own reply?

Expected Result: The user comments 'fruit', the bot responds with 'apple' and leaves an apple emoji 🍎 on its own comment

Actual Result: The user comments 'fruit', the bot responds with 'apple' and leaves an apple emoji 🍎 on the user's comment instead

bot.on('message', msg => {

  if(msg.content === 'fruit'){

    msg.reply('apple').then();
    msg.react('🍎');

  }

})

I've also tried the following:

 bot.on('message', msg => {

  if(msg.content === 'fruit'){

     msg.reply('apple').then(react('🍎'));

  }

})

But it results in an error: 'react is not defined'

Thank you in advance

Upvotes: 0

Views: 70

Answers (2)

Nulji
Nulji

Reputation: 457

You need to use the result of the message reply inside the then of of the promise :

bot.on('message', msg => {
  if (msg.content === 'fruit') {
    msg.reply('apple').then((botMsg) => botMsg.react('🍎'));
  }
});

(You can have the message created inside the then, it means that the promise successed)

Upvotes: 2

Worthy Alpaca
Worthy Alpaca

Reputation: 1245

This is super easy to solve. All you have to do is use an arrow function inside the .then.

msg.reply('apple').then(m => m.react('🍎'));

Upvotes: 2

Related Questions