简体   繁体   English

Discord.js 反应收集器不适用于自定义表情符号

[英]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.我在编写机器人时遇到问题,我的反应收集器将使用 Unicode 表情符号,但不是我服务器的自定义表情符号。 I want the reaction to send a message into the channel.我希望反应向频道发送消息。 It currently only works with Unicode emojis.它目前仅适用于 Unicode 表情符号。 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.如果您使用的是awaitReactions方法,那么您的 promise 未实现。 Check this for more info. 检查此以获取更多信息。 To solve this, all you have to do is add return to your program , thus fulfilling the promise.要解决这个问题,您只需在程序中添加return ,从而实现 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.代替message.channel.send("Smile")message.channel.send("Peasant") ,发送return message.channel.send("Smile")return message.channel.send("Peasant")

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.只需将reaction.emoji.name 设置为表情符号的实际名称,而不是用于显示表情符号的文本。 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:在一些假设的情况下,如果另一个表情符号的文本是 <:hypotheticalemojiname:837837383738373>,那么检查反应是否是那个表情符号的方法是:

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

Hope this helped!希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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