【问题标题】:(node:47028) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emoji' of undefined(节点:47028)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“表情符号”
【发布时间】:2020-08-01 23:37:49
【问题描述】:

为什么它给我这个错误?如何定义表情符号? IT 应该只检查反应是否与那个表情符号有关。

.then(function (message, reaction) {
                message.react("????")
                message.react("????")

                const filter = (reaction, user) => {
                    return ['????', 'B'].includes(reaction.emoji.name) && user.id === message.author.id;
                };

                message.awaitReactions(filter, { max: 1 })
                    .then(collected => {
                        if (reaction.emoji.name === '????') {
                            message.channel.send('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
                        }
                        else {
                            message.channel.send('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.');
                        }    
                    })
            });

【问题讨论】:

    标签: javascript bots discord.js emoji defined


    【解决方案1】:

    reaction 不会通过您在显示代码之前直接调用的任何方法返回。从回调函数中删除参数。然后,要访问应用的反应,您需要从Message#awaitReactions() 返回的Collection 中读取它。比如……

    .then(collected => {
      const reaction = collected.first();
      // now you can check the reaction with the code you were using
    })
    

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2020-08-18
      • 2020-12-11
      • 1970-01-01
      • 2019-12-15
      • 2021-08-31
      • 2021-09-01
      • 2021-07-05
      • 1970-01-01
      相关资源
      最近更新 更多