I have imported net.dv8tion.jda.api.entities.emoji.Emoji and below is the code written
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(Color.green);
event.getChannel().sendTyping().queue();
event.getChannel().sendMessage("").setEmbeds(embed.build()).queue(message -> {
message.addReaction("✔").queue();
});
When running the code above, the error java: incompatible types: java.lang.String cannot be converted to net.dv8tion.jda.api.entities.emoji.Emoji occurs.
You have to create an instance of Emoji
. It offers various factory methods:
In your case, the string you have is a unicode emoji. To use it as a reaction, simply wrap it in Emoji.fromUnicode(...)
.
Example: message.addReaction(Emoji.fromUnicode("✔")).queue()
Note that you should also make sure that your files and compiler use UTF-8 if you directly paste emoji this way. To avoid issues with encoding you can use the codepoint notation instead. You can find the codepoint notation by searching for ✔ unicode
on your search engine of choice.
Example: message.addReaction(Emoji.fromUnicode("U+2713")).queue()
For performance reasons, it is recommended to store these emoji instances in static final fields.
public class Emojis {
public static final Emoji CHECKMARK = Emoji.fromUnicode("U+2713");
}
Then you can just use it like this: message.addReaction(Emojis.CHECKMARK).queue()
.