Java JDA Discord app - Can't add reaction to received messages

Joe JJJ :

I'm trying to add a custom emote to messages that contain certain words. I've tried using the addReaction(Emote) and addReaction(String) methods in every way I can find. I just can't get the bot to add reactions to a message (its also not working with unicode emojis).

I've used the following methods below

event.getMessage().addReaction("name:XXXXXXXXXXXXXXXX");
event.getMessage().addReaction("name");
event.getMessage().addReaction("XXXXXXXXXXXXXXXX");
event.getMessage().addReaction(Emote emote);

It just seems to not work any way. Can someone point me in the right direction please?

The bot does a lot of other functions that all work fine. I do have a CS degree in Java so I have a good idea of how to write and structure code.

Eldar B. :

JDA uses RestActions, they basically allow to queue all the actions into Discord and without them, your commands won't be sent to Discord. Your code doesn't work because you've forgotten to include the RestAction.

As to your attempts to add a reaction, read the relevant JDA Docs to get an idea of what you should type in the parameters.

In short, you can either use the Emote instance or an emote Unicode. There are a few ways to retrieve an emote's Unicode, for instance, Emoji Unicode Table.

You can also use the bot located at the official JDA Discord Server by sending the next message: %emote EMOJI (replace EMOJI with an actual emoji) which will be replied with the Emote's unicode.

Note that the bot provides two different UTFs (UTF32 and UTF16) while the table provides only UTF32, and it is more recommended to use UTF16. Example: :smile: emote - \u1F604 UTF32 [\uD83D\uDE04] UTF16.

Then, simply paste the Unicode as a String as the parameter of addReaction. Make sure there is only one \ and not two, since the IDE can automatically add an escape character in some cases. Examples to correct and incorrect usages:

CORRECT - addReaction("\uD83D\uDE04").queue(); // reacts with :smile:

INCORRECT - addReaction("\\uD83D\\uDE04").queue(); // reacts with :smile:

CORRECT - addReaction("U+1F604").queue(); //reacts with :smile:

CORRECT - addReaction("\u1F604").queue(); // reacts with :smile:

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=379683&siteId=1