Skip to content

Using application emojis

Long gone are the days when you had to add emojis to your own guilds, you can now add up to 2000 emojis on your application.

While you can add them manually in your dashboard, they are:

  • Not very practical
  • Requires you to hardcode them (unless you fetch them yourself, but that's even more effort)
  • Can only be used for one application, making it annoying when you switch from a test bot to your production bot.

Which is why you can let the framework upload them for you! It will upload them after JDA logs in, but before it comes online.

Enabling the feature

You need to enable the feature explicitly, in your BotCommands entry point, go to the appEmojis configuration, and enable the feature.

BotCommands.create {
    // ...

    appEmojis {
        enable = true
    }
}
BotCommands.create(builder -> {
    // ...

    appEmojis(appEmojis -> {
        appEmojis.enable(true);
    });
});

Making an application emoji container

The first step is to create a class that will hold your application emojis, you will need to annotate it with @AppEmojiContainer, which tells the library to load all ApplicationEmoji fields inside it.

By default, this will search emojis in the /emojis resource folder, but you can change it in the annotation.

Registering/retrieving application emojis

Eager retrieval

You can use delegated properties on AppEmojisRegistry to get an application emoji from your property's name, for example:

@AppEmojiContainer // Here you can change the base location of all emojis contained here
object AppEmojis {
    // This annotation is optional,
    // you can use it to change where the emoji is fetched from,
    // or how it will be named on Discord.
    @AppEmoji(emojiName = "kotlin_eager")
    val kotlin: ApplicationEmoji by AppEmojisRegistry
}

You can use AppEmojisRegistry.get, pass it the name of your field, for example:

@AppEmojiContainer // Here you can change the base location of all emojis contained here
public class AppEmojis {
    // This annotation is optional,
    // you can use it to change where the emoji is fetched from,
    // or how it will be named on Discord.
    @AppEmoji(emojiName = "java_eager")
    public static final ApplicationEmoji java =
            // The field name must be the same as the string passed
            AppEmojisRegistry.get("java");
}

Warning

You must not initialize the class before the emojis are loaded, in other words, you can only access your fields/properties once they have been retrieved. You typically don't need to do anything but to use the emojis when they are actually needed.

Lazy retrieval (Kotlin only)

Similar to eager retrieval, you can use delegated properties on AppEmojisRegistry.lazy, for example:

@AppEmojiContainer
object LazyAppEmojis {
    // Can't use @AppEmoji here, you can override stuff in the function call
    val kotlin: ApplicationEmoji by AppEmojisRegistry.lazy(::kotlin, /* Overrides default values */ emojiName = "kotlin_lazy")
}

As always, you cannot use the emoji before it is loaded, however, loading the object itself is fine.