How do ReactionEmojis work in discord4j 3.1.0

1.2k Views Asked by At

I'm currently working on a bot with discord4j where I want to add a reaction(emoji) to a message. But i have no clue, how to use the addReaction() method and every example i find is using an older version. In earlier versions of dicord4j you could give a string of the unicode representation of the emoji as the parameter, but now it just takes in an object of the type ReactionEmoji. I looked at its methods nothing really makes sense except the ReactionEmoji.unicode(String raw) but then i get the error-message "unknown emoji". As input of the string i tried the unicode, the actual emoji itself, and i went into debug mode, added a reaction to a message, then took the reaction in debug mode, and copied the raw value of the reaction, pasted it as the input parameter of the unicode() mehtod , but it still didn't recognize it as an emoji. Is there some documentation i can't find? My code :

Message msg = channel.createMessage("Test").block();
msg.addReaction("U+2B06").block();
2

There are 2 best solutions below

1
Minn On BEST ANSWER

You have to use a unicode escape instead:

channel.createMessage("Test")
       .flatMap(msg -> msg.addReaction(ReactionEmoji.unicode("\u2B06")))
       .subscribe();

For documentation refer to addReaction and ReactionEmoji

0
Diogo Fernandes On

For multiple reactions

 channel.createMessage("Test").flatMap(msg -> 
 msg.addReaction(ReactionEmoji.unicode(""))
                    .then(msg.addReaction(ReactionEmoji.unicode(""))))
.subscribe();