【问题标题】:discord.js reaction method outputs wrong emoji{已解决} discord.js 反应方法输出错误的表情符号
【发布时间】:2021-08-13 11:06:22
【问题描述】:

我需要帮助我目前的方法没有得到正确的反应表情符号。但我希望它获得正确的表情符号。有人可以帮我吗?

bot.on('messageReactionAdd', async (reaction, user) => {
    const message = reaction.message
    if (reaction.partial) {
    try {
        await reaction.fetch();
    } catch (error) {
        console.error('Something went wrong when fetching the message: ', error);
        return;
    }

    if(user.bot) return;
    if(reaction.emoji == "????"){
        reaction.message.channel.send("Right emoji")
        reaction.message.reactions.cache.get("????").remove(user);
        reaction.message.react("????")

        let category = message.guild.channels.cache.find(cat=> cat.name === "my category")

        if(category == null){
            message.guild.channels.create('my category', { type: 'category' })
            .catch(console.error);
            category = message.guild.channels.cache.find(cat=> cat.name === "my category")
        }

        setTimeout(createShopTicketChannel, 2000, message, category, user, "????")
    }else if(reaction.emoji == "????"){
        reaction.message.channel.send("Wrong emoji")
        reaction.message.reactions.cache.get("????").remove(user);
        reaction.message.react("????")

        let category = message.guild.channels.cache.find(cat=> cat.name === "my category")

        if(category == null){
            message.guild.channels.create('my category', { type: 'category' })
            .catch(console.error);
            category = message.guild.channels.cache.find(cat=> cat.name === "my category")
        }

        setTimeout(createShopTicketChannel, 2000, message, category, user, "????")
    }else{
        message.channel.send("Wrong emoooji")
    }
}

输出是:错误的表情符号,即使我对正确的表情做出反应。

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    要解决此问题,您应该使用 reaction.emoji.name 而不是 reaction.emoji。如果您要添加更多案例,我还建议使用switch 而不是多个 if-else 语句。

    切换文档 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

    希望对您有所帮助:)

    【讨论】:

      猜你喜欢
      • 2021-05-20
      • 2020-11-14
      • 2021-08-11
      • 2022-08-19
      • 2021-08-04
      • 2018-09-25
      • 1970-01-01
      • 2020-07-09
      • 2021-08-14
      相关资源
      最近更新 更多