Skip to content

freya022/jda-emojis

Repository files navigation

JDA Emojis

This is a lightweight and convenient alternative to JEmoji, from which it is generated from.

Assuming you only need to use the emojis, you can use them directly with JDA instead of having to convert them!

Installation

jda-emojis-maven-central-shield

The minimum Java version supported is Java 11.

Kotlin Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation("dev.freya02:jda-emojis:$version") // replace $version with the latest version
}

Maven

<dependency>
    <groupId>dev.freya02</groupId>
    <artifactId>jda-emojis</artifactId>
    <version>${version}</version> <!-- replace ${version} with the latest version -->
</dependency>

Usage

There are two classes you can use Emojis and UnicodeEmojis, you can use either of them, they are the same.

This library only provides known emojis as constants, if you need to retrieve them from a string, you will have to use JEmoji.

Examples

Buttons

Button approve = Button.primary("approve:data", "Approve").withEmoji(Emojis.WHITE_CHECK_MARK);

Select menus

StringSelectMenu choices = StringSelectMenu.create("choices:data")
        .addOptions(
                SelectOption.of("First choice", "1").withEmoji(Emojis.ONE)
        )
        .build();

Reactions

MessageCreateData messageData = new MessageCreateBuilder()
        .addActionRow(approve)
        .addActionRow(choices)
        .build();

event.reply(messageData)
        // Since we reply to a slash command, we need to retrieve the message back
        .flatMap(InteractionHook::retrieveOriginal)
        // This emoji's name is slightly different as fields can't start with digits
        .flatMap(message -> message.addReaction(Emojis.HUNDRED_POINTS))
        .queue();

example.png

License

This project is licensed using the Apache 2.0 license.

The code was also partially generated from JEmoji, using the same license.