Skip to content

azzerial/slash-commands

Repository files navigation


Slash Command icon

Slash Commands

An open source utility library for JDA to simplify the use of Discord Slash Commands

FeaturesHow To UseInstallationLicense


Features

A few things you can do with the library:

  • Create and manage Slash Commands
  • Assign callbacks to Slash Commands (supports per command path and wildcard callbacks)
  • Assign callbacks to message components:
    • Buttons
    • Selection Menus
  • Bind data to a message component:
    • Raw data buffer
    • Session storage

How to Use

@Slash.Tag("ping_command")
@Slash.Command(
    name = "ping",
    description = "Check if the application is online"
)
public class PingCommand {

    public static void main(String[] args) throws LoginException, InterruptedException {
        final JDA jda = JDABuilder.createDefault(...)
            .build()
            .awaitReady(); // wait for JDA to be connected (mandatory)
        final SlashClient slash = SlashClientBuilder.create(jda)
            .addCommand(new PingCommand()) // register the ping command
            .build();

        slash.getCommand("ping_command") // get the ping command by it's @Slash.Tag
            .upsertGuild(...); // upsert it as a guild Slash Command
    }

    @Slash.Handler()
    public void callback(SlashCommandEvent event) {
        event.deferReply()
            .setContent("pong!")
            .queue();
    }
}

For more examples and usage guides, please refer to the wiki and the playground module.

Installation

This project uses Jitpack.

Latest release:

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.azzerial.slash-commands:api:1.1'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.azzerial.slash-commands</groupId>
    <artifactId>api</artifactId>
    <version>1.1</version>
</dependency>

License

This project is licensed under the Apache License 2.0 © 2021 Robin Mercier.


Slash Commands by Robin Mercierazzerial.net