JDADiscordBot is a modular and flexible Discord bot built with the Java Discord API (JDA). The bot supports both prefix-based commands (e.g., !ping
) and Discord's newer slash commands (e.g., /ping
). This design allows for an organized and streamlined setup where you can easily add or modify commands to suit your server's needs.
- Prefix-Based Commands: Traditional commands activated by a customizable prefix, such as
!ping
. - Slash Commands: Built-in support for Discord's modern slash commands (e.g.,
/greet
). - Easy to Configure: Use environment variables to configure sensitive information like the bot token and command prefix.
- Scalable Command Management: Handlers are in place to simplify adding and managing both prefix and slash commands.
- Support Server: Join our support server for assistance or to offer suggestions.
- Java 17 or higher installed on your system.
- Gradle for dependency management and building the project.
To get started, clone the repository to your local machine.
git clone https://github.com/ferrymehdi/JDADiscordBot.git
cd JDADiscordBot
Create a .env
file in the root directory to securely store the bot's token and command prefix.
Sample .env
file:
TOKEN=your_discord_bot_token_here
PREFIX=!
JDADiscordBot relies on the following main dependencies:
- JDA (Java Discord API) - Version 5.2.0 for connecting and interacting with Discord.
- dotenv-java - For handling environment variables securely.
Once your environment variables are set up and dependencies are installed, you can start the bot using Gradle:
./gradlew run
JDADiscordBot has a clear structure for handling both prefix and slash commands. The bot is split into two main handlers:
- PrefixCommandsHandler: Handles commands prefixed by the customizable
PREFIX
(e.g.,!ping
). - SlashCommandsHandler: Manages Discord's native slash commands (e.g.,
/greet
).
- Create a new class in
org.ferry.PrefixCommands.Commands
that implementsPrefixCommand
. - Implement the
execute
method to define the command's action. - Add your command to
PrefixCommandsHandler
by callingaddCommand(new YourCommand())
.
- Create a new class in
org.ferry.SlashCommands.Commands
that implementsSlashCommand
. - Implement the
execute
method and define thegetCommand
method to register the command with Discord. - Add your slash command to
SlashCommandsHandler
by callingcommands.add(new YourCommand())
in its constructor.
If you have questions, encounter issues, or want to contribute, join our support Discord server. We’re here to help and appreciate feedback.
This project is licensed under the MIT License. See the LICENSE
file for details.
Feel free to fork this project, submit issues, or suggest enhancements. Contributions are welcome, and detailed pull requests will be reviewed as soon as possible.
Enjoy customizing and running JDADiscordBot for your Discord server!