'discord.js reaction method outputs wrong emoji

I need help with my current method which doesn't get the right reaction emoji. But I want it to get the right Emoji. Can someone help me?

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")
    }
}

the output is: Wrong emoooji, even when I react with the right one.



Solution 1:[1]

To fix this issue you should use reaction.emoji.name instead of reaction.emoji. Also I recommend using switch instead of multiple if-else statements if you're going to add a few more cases.

Switch documentation - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

Hope it helped :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FrostyTheDumDum