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.
Adding EnhancedJDA to your project
EnhancedJDA requires at least JDK 17
- Gradle
- Maven
repositories {
mavenCentral()
}
dependencies {
implementation 'dev.projectenhanced:EnhancedJDA:{VERSION}'
}
<dependency>
<groupId>dev.projectenhanced</groupId>
<artifactId>EnhancedJDA</artifactId>
<version>{VERSION}</version>
</dependency>
Suggested plugin - Lombok
- Gradle
- Maven
plugins {
id "io.freefair.lombok" version "8.11"
}
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
</dependencies>
Example build configuration
- Gradle
- Maven
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]"
)
}
}
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>[PATH_TO_MAIN_CLASS]</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
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);
}
}
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());