Hey I’m doing a bot and I need to get the name of the emoji from the reaction. I did it for now with console.log ()
but I was surprised because I got some kind of weird badge instead of the emoji name.
I got the emoji 🎉 :tada:
for the news and I was expecting something like this in the name of this emoji. Meanwhile, I received such a thing �. Is this a problem with me or did I do something wrong? Please help.
//------------------------------ 📁 index.js //------------------------------ client.on('messageReactionAdd', async (reaction) => { console.log(reaction.emoji.reaction) }) //------------------------------ Below console output //------------------------------ _emoji: ReactionEmoji { animated: undefined, name: '�', id: null, deleted: false, reaction: [Circular] },
Advertisement
Answer
Unfortunately there is no direct way to get the name of a built-in discord emoji.
Discord uses Twemoji and only references them by ID. Thus, you’d have to map the Emoji’s Unicode to the actual emoji name somehow.
There are libraries such as emoji-dictionary that can help with that:
let emojiDic = require("emoji-dictionary"); // ... client.on("messageReactionAdd", async(reaction) => { console.log(emojiDic.getName(reaction.emoji.toString())); // -> "tada" });
Note: You won’t be able to re-use that name in discord. For instance, this code will NOT work:
message.channel.send(":" + emojiDic.getName(reaction.emoji.toString()) + ":");
You have to either send by Unicode directly, or by the Emoji’s ID.