Skip to content

Getting Started

Dynxsty edited this page Nov 13, 2022 · 1 revision

Installation

This version of DIH4JDA must be used with the following version of JDA: net.dv8tion:JDA:5.0.0-alpha.22

DIH4JDA itself is distributed through Maven Central:

Maven

<dependency>
  <groupId>xyz.dynxsty</groupId>
  <artifactId>dih4jda</artifactId>
  <version>1.6</version>
</dependency>

Gradle

dependencies {
    [...]
    implementation("xyz.dynxsty:dih4jda:1.6")
}

Getting Started

Creating a new DIH4JDA instance is fairly easy:

DIH4JDA dih4jda = DIH4JDABuilder
        .setJDA(jda) // Your JDA instance
        .build();

Now, you get to decide how you want your commands to be registered:

Manual Command Registration

To manually register commands, use the following methods, AFTER you've .build(); your DIH4JDA instance, like that:

DIH4JDA dih4jda = DIH4JDABuilder
        .setJDA(jda) // Your JDA instance
        .build();
dih4jda.addSlashCommands(new PingCommand(), new HelloWorldCommand());
dih4jda.addContextMenus(new PingUserContext(), new HelloWorldMessageContext());

Automatic Command Registration

Alternatively, you can specify packages on the DIH4JDABuilder instance which will be scanned for all classes that extend one of the following classes:

  • SlashCommand
  • ContextCommand.User
  • ContextCommand.Message
DIH4JDA dih4jda = DIH4JDABuilder
        .setJDA(jda) // Your JDA instance
        .setCommandPackages("xyz.dynxsty.bot.commands") // OPTIONAL: The package(s) that contains all your commands
        .build();

Upon calling .build();, the bot will register all commands that are in the specified package(s).

Clone this wiki locally