简体   繁体   中英

How do I make the bot react to itself with 2 different reactions

I am trying to allow the bot to react to itself with both thumbs up and down. here is my code:

const args = message.content.split(' ');
if (message.content.includes('<poll')) {
  message.delete()
  let embed = new Discord.MessageEmbed()
  .setTitle(`Poll In ${message.guild.name}`)
  .setDescription(args.slice(1).join(' '))
  .setFooter(`Started by ${message.author.username}`)
  .setColor('#ffc0cb')

  message.channel.send(embed)
  .then(sentMessage => sentMessage.react('👍'))
  .catch(console.error)
}

I tried using .then twice but it didn't work.

Try this:

message.channel.send(embed)
   .then(sentMessage => {
      sentMessage.react('👍')
      sentMessage.react('👎')
});

If you want your bot to react in order you have two options:

Option 1:

Use async / await :

message.channel.send(embed)
   .then(sentMessage => {
      // Don't forget to make your function async, otherwise it won't work
      await sentMessage.react('👍')
      await sentMessage.react('👎')
});

Option 2:

Chain .then() 's:

message.channel.send(embed)
   .then(sentMessage => sentMessage.react('👍'))
   .then(sentMessage => sentMessage.react('👎'))
});

References:

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