JDA-Newtils is a modern series of tools and utilities for use with JDA to assist in bot creation.
You will need to add this project as a dependency (via Maven or Gradle), as well as JDA.
The minimum java version supported by JDA-Newtils is Java SE 11.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories><dependency>
<groupId>com.github.SaseQ</groupId>
<artifactId>JDA-Newtils</artifactId>
<version>$version</version> <!-- replace $version with the latest version -->
</dependency>dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation 'com.github.SaseQ:JDA-Newtils:$version' // replace $version with the latest version
}We provide a number of examples to introduce you to JDA-Newtils. You can also take a look at our official Wiki.
Starting your bot and setup default JDA-Newtils configuration:
public static void main(String[] args) {
JDA jda = JDABuilder.createDefault("$token") // replace $token your discord bot token
.build();
CommandManager manager = new CommandManager();
manager.setOwnerId("$owner_id"); // replace $owner_id with your user discord id
manager.setDevGuildId("$dev_guild_id"); // replace $dev_guild_id with your discord server id (remove this line on prod)
manager.addCommand(new Ping());
jda.addEventListener(manager);
}Example of how to create a ping SlashCommand which we registered earlier in the main function:
public class Ping extends SlashCommand {
public Ping() {
this.name = "ping";
this.description = "Performs a ping to see the bot's delay";
}
@Override
public void execute(@NonNull SlashCommandInteractionEvent event) {
event.reply("Ping: ...").queue(m ->
m.editOriginal("Pong! " + event.getJDA().getGatewayPing() + "ms").queue()
);
}
}A more detailed examples with other JDA-Newtils tools can be found in the Wiki.