简体   繁体   中英

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

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('🍎'));

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM