3

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 )

Yawrf
  • 71
  • 1
  • 7

1 Answers1

2

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.

  • Yeah, I'm trying to avoid doing it manually because I want it to be able to dynamically grab it, and I was hoping to avoid needing a library but it seems I may not have a choice. Thanks for the links! – Yawrf May 02 '21 at 17:15
  • 1
    Ok now I need to add to this that apparently I'm also just dumb. In message.content, unicode emojis are actually represented as their unicode part, not as ```<:robot:838287833931317288>```, so a regex that captures emojis (such as ```/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu```) will get the emojis that you need – Yawrf May 02 '21 at 17:58