(节点:47028)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性'emoji'

时间:2020-04-19 14:31:43

标签: javascript bots discord.js emoji defined

为什么给我这个错误?如何定义表情符号? 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>.');
                        }    
                    })
            });

1 个答案:

答案 0 :(得分:1)

在显示代码之前,您直接调用的任何方法都不会返回

reaction。从回调函数中删除参数。然后,要访问应用的反应,您需要从Message#awaitReactions()返回的Collection中读取它。例如...

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