Skip to main content

Getting Started

EnhancedJDA is an advanced library that enhances the Java Discord API for creating powerful Discord bots. It simplifies development with built-in tools for command parsing, event handling, database & config management and advanced features like slash commands and message components.

With intuitive syntax and ready-to-use templates, EnhancedJDA reduces complexity and enhances productivity. Whether you're building a simple bot or a complex application, EnhancedJDA makes Discord bot development in Java effortless and efficient.

Example usage of EnhancedJDA

Adding EnhancedJDA to your project

note

EnhancedJDA requires at least JDK 17

build.gradle
repositories {
  mavenCentral()
}

dependencies {
  implementation 'dev.projectenhanced:EnhancedJDA:{VERSION}'
}
Suggested plugin - Lombok
build.gradle
plugins {
  id "io.freefair.lombok" version "8.11"
}

Example build configuration

build.gradle
plugins {
id "com.github.johnrengelman.shadow" version "8.1.1"
}
shadowJar {
archiveFileName = project.name + "-" + project.version + ".jar"
manifest {
attributes(
"Main-Class": "[PATH_TO_MAIN_CLASS]"
)
}
}
note

Don’t forget to replace [PATH_TO_MAIN_CLASS]

Project Template

To start developing your bot, extend your main class using EnhancedBot class and call runBot() in the main method.

public class Main extends EnhancedBot {
public static void main(String[] args) throws ReflectiveOperationException {
runBot(Main.class);
}
}
note

Starting the bot for the first time will generate .env file in the work directory. You need to configure it before using the bot.

ENV=<DEV / PRODUCTION>
TOKEN=<DISCORD BOT TOKEN>
DATABASE=<SQLITE or MYSQL Connection URL>

Extending EnhancedBot class gives you some methods that you can override.

@Override
public void preBuild(DefaultShardManagerBuilder builder) {
    // This method will be executed just before building ShardManager
// You can modify builder by i.e. changing bot status and activity:
// builder.setStatus(OnlineStatus.DO_NOT_DISTURB);
// builder.setActivity(Activity.customStatus("uD83DuDEE0uFE0F Working on EnhancedJDA"));
}

@Override
public void postBuild(ShardManager shardManager) {
// This method will be executed just after building ShardManager
}

@Override
public void onReady(ReadyEvent event) {
    // This method will be executed when bot is ready. I.e you can log it
    // EnhancedLogger.getLogger().info("Logged as {}", event.getJDA().getSelfUser().getAsTag());
}

@Override
public void onShutdown() {
    // This method will be executed just before exiting bot
}

Logs

All logs will be saved in logs folder inside the work directory. To log something, use EnhancedLogger utility class.

Example from the ⁣onReady method:

 EnhancedLogger.getLogger().info("Logged as {}", event.getJDA().getSelfUser().getAsTag());