Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.js getting Unicode emojis from message.content

I'm currently trying to create a bot that reacts to a message that pings it with whatever emoji is included in the message that pings it (So for example @Robot#1234 :robot: would get a :robot: reaction). I've easily figured out how to identify the emojis sent, and reacting with custom emotes is easy (as you can just do message.react("<:customRobot:12345>");). But, as every google listing will tell you, you have to get the actual unicode representation of whatever emoji you want to react with if you're going to use it, so you can't just do message.react("<:robot:838287833931317288>");.

With that being said: Is there any way to dynamically find and convert the <:name:id> representation of a unicode emoji into the actual string form of a unicode emoji? (Which for :robot: would be 🤖)

like image 510
Yawrf Avatar asked Dec 22 '25 15:12

Yawrf


1 Answers

It looks like the emoji-name-map module might be helpful here: https://github.com/IonicaBizau/emoji-name-map. Includes a conversion from the string format to the character itself (i.e., the unicode representation), which I think you can then use with message.react in discord.js.

Extras: There's also a module emoji-unicode (https://github.com/IonicaBizau/emoji-unicode) to get the raw unicode values from the character itself if you really need them, or there are some other stack overflow answers that explain how to do this manually if you'd rather avoid importing a library: see https://stackoverflow.com/a/48419805 or https://stackoverflow.com/a/37729608.

like image 162
Travis Bartholome Avatar answered Dec 24 '25 03:12

Travis Bartholome