1

How can I check, which reaction was added to a message? I want to create a command (!roles) with some reaction and if you click on one, you get a role. I tried like this:

if(event.getReactionEmote().emote == ":salt:") {
    Guild guild = event.getGuild();
    guild.addRoleToMember(event.getMember(), guild.getRoleById("*ROLEID*")).queue();
}

But it does not work.

iknow
  • 8,358
  • 12
  • 41
  • 68
Jan
  • 19
  • 3
  • 1
    You should be using `event.getReactionEmote().emote.equals(":salt:")` the equality operator doesn't work with strings in Java for reasons i wont get into here. Even better: `":salt:".equals(event.getReactionEmote().emote)` which guards against emote being null. [This question](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) may be helpful. – Waltzy Aug 17 '20 at 22:53
  • thanks for answering... but the if does not work :/ `if(":salt:".equals(event.getReactionEmote().getEmoji())) { System.out.print("test"); }` but i tested, `event.sendMessage(event.getReactionEmote().getEmoji()).queue();` and it sends the right emoji in the channel. – Jan Aug 18 '20 at 22:17

1 Answers1

2

Use event.getReactionEmote().getEmoji.equals("EMOTE") where "EMOTE" equals the emoji you want.

You may use EmojiTerra to find the correct code for the emoji of your liking. (You can find it at "Emoji - Codes". Use the code for "Java, JavaScript & JSON".)

Example: The correct code for salt is \uD83E\uDDC2.

Danny
  • 822
  • 1
  • 9
  • 30