Replies: 1 comment 5 replies
-
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
About
JDA supports Emotes and Emojis in various places like messages or reactions.
It can however get a bit confusing on either how you use it or where you can use what format.
What are Emotes and what are Emojis?
As Emotes does JDA usually refer to custom Emojis by Discord.
Unlike Emojis, which are Unicode are Emotes in a different format.
Formats (Emojis)
As mentioned before are Emojis Unicode and depending on where you use them can you use two different types of formats:
\u2705
(✅)Message#addReaction(String)
) can you use the raw Unicode-Format but also the Codepoint format (U+2705
).It's worth mentioning, that the Codepoint representation may have a different format than the Unicode one as it usually is only a single piece while Unicode can be made out of several parts.
Pro-tip: Number Emojis (1️⃣)
If you want to use any of the Numbered Emojis (
:zero:
(0️⃣) to:nine:
(9️⃣)) can you save some work by simplifying the Emoji's Unicode format.The emoji itself is put together from 2 separate Unicodes: The first one is the number, and the second one the square surrounding it. There is usually also a "Regional Indicator" put in-between those two but it can often be omitted without problems.
So if you f.e. want to display 1️⃣ can the full code (
\u0031\u20E3
) be simplified to1\u20E3
since the first part itself is the number.This also allows us to have a much simpler system to f.e. add multiple number reactions to a message:
Formats (Emotes)
Since Emotes are Discord's custom Emojis do they also follow their own unique pattern to use in messages and reactions.
<:_name_:_id_>
is used for displaying normal, non-animated Emotes<a:_name_:_id_>
is used for displaying animated EmotesSomething that is worth pointing out is, that
_name_
can be any text you like as long as the_id_
is a valid Emote ID.IDs of Emotes cannot be retrieved the normal way as you can do with IDs of channels, messages, etc.
Instead what you need to do is escape the Emote by prefixing it with a backslash (
\:emoteName:
) in the Textarea of the Discord Client to reveal the "raw" format. From there can you then take the ID from the corresponding section.Usage in Reactions
The
addReaction
method of JDA has an option that allows you to provide the Emote through a simple String instead of the Emote Object itself.This allows you to essentially skip getting the Emote (
Guild#getEmoteById(long)
) and instead directly add the reaction.In this quick example do we use the JDA Emote (
<:jda:230988580904763393>
)Animated Emotes need to be prefixed with
a:
similar to how they're prefixed in their raw format.Summary
Here is a quick summary of what you should've learned now:
\u<code>
) for Emojis and the "raw" format of Emotes (Can be achieved usingEmote#getAsMention()
)_name_:_id_
/a:_name_:_id_
format (Obviously replace_name_
and_id_
with the actual values).Common Questions
Can I use
:name:
instead of the Unicode?No.
The
:name:
depends on the OS you use and can therefore be different while the Unicode is always the same. Because of this does JDA not have any direct support for using the:name:
pattern to use Emojis in Messages or reactions.It may work but it's not guaranteed.
You can add this support to your bot yourself by using an Emoji library for Java tho.
Can my Bot use Emotes from other Guilds?
Yes, as long as the bot is on this Guild.
The only Entity allowed to use Emotes without this requirement is Webhooks. Those can use any Emote as long as the pattern is correct.
Can I escape an Emoji to get its raw Unicode?
Not directly.
Escaping the Emoji (Prefixing it with a backslash) will only reveal the actual Emoji used. Discord uses Twemoji which makes them look the same across all platforms (with the exception for reactions) and escaping the Emoji will show the actual Emoji, which will look different per OS (See the Emojipedia for the different looks)
Similar to the first question can you use an Emoji Library to get the Unicode from an Emoji in a message, or look it up on Emojipedia.
Beta Was this translation helpful? Give feedback.
All reactions