简体   繁体   中英

Discord.js reaction collector wont work with custom emojis

I have been having a problem while coding my bot where my reaction collector will work with Unicode emojis, but not my server's custom emojis. I want the reaction to send a message into the channel. It currently only works with Unicode emojis. Is there a certain way I should be doing this?

        .then(collected => {
          const reaction = collected.first();

          if (reaction.emoji.name === "😀") {
            message.channel.send("Smile")
            
          }
          
          if (reaction.emoji.name === "<:Peasant:797613974173515786>") {
            message.channel.send("Peasant")
          }
        
          
        })```

If you're using the awaitReactions method, then your promise is unfulfilled. Check this for more info. To solve this, all you have to do is add return to your program , thus fulfilling the promise.

Instead of message.channel.send("Smile") and message.channel.send("Peasant") , send return message.channel.send("Smile") and return message.channel.send("Peasant") instead.

I experienced the same issue recently,but luckily I figured it out!

Simply set reaction.emoji.name to the actual name of the emoji,and not the text you use for displaying the emoji. For example,in your case,it would be:

if (reaction.emoji.name == 'Peasant') {
   // do stuff
}

And in some hypothetical case,if the text for another emoji was <:hypotheticalemojiname:837837383738373>,the way to check if the reaction was that emoji would be:

if (reaction.emoji.name == 'hypotheticalemojiname') {
   // Do stuff
}

Hope this helped!

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