A customizable Discord bot developed with Java.
- 📝 Command-based structure
- ⚡ Event listeners
- 🧩 Easily extensible architecture
- 🛠️ Modern Java and Gradle usage
- ☕ Java 17 or higher
- 🛠️ Gradle (or local setup with
gradlew
) - 🔑 A Discord bot token (Discord Developer Portal)
- 📥 Clone the repository:
git clone https://github.com/Xjectro/java-discord-bot.git cd java-discord-bot
- 📦 Install dependencies and build:
./gradlew build
-
🔐 Add your bot token and (optionally) database connection string to the
app/.env
file. Example:DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN MONGO_URI=mongodb://localhost:27017
-
🚀 Start the bot:
./gradlew run
After adding the bot to your server, you can use the following commands:
-
!autorole <enabled|disabled> [@role1 @role2 ...]
- 🔄 Enables or disables the auto role system and sets the roles to assign.
- 💡 Example:
!autorole enabled @Member @Registered
-
Slash command version:
/autorole status:<enabled|disabled> roles:@role1,@role2,...
- 💡 Example:
/autorole status:enabled roles:@Member,@Registered
⚠️ You need the Manage Roles permission to use these commands.
!ping
— Checks if the bot is running.
- 🗂️ To add new commands, create a new class in the
app/src/main/java/org/example/commands/
directory.
Contributions are welcome! Please open an issue before submitting a pull request.
This project is licensed under the MIT License.
- 👤 Developer: Xjectro
- 👤 Developer2: range79
- 🔗 Project Link: github.com/Xjectro/java-discord-bot
- ☕ Java 17+: Main programming language.
- 🛠️ Gradle: Build and project management tool.
- 🤖 JDA (Java Discord API): Core library for Discord bot functionality.
- 🍃 MongoDB: NoSQL database for storing server-specific settings and data.
- 🟢 Morphia: ORM library for easy data access between Java and MongoDB.
- 🗝️ dotenv-java: Loads environment variables from
.env
files.
- 📝 Command System: All commands are in the
org.example.commands
package, making it easy to add new ones. - ⚡ Event System: Handles Discord events under
org.example.events
. - 🗄️ Database Management: MongoDB connection and models are under
org.example.database
. Server-specific settings (e.g., auto role) are stored in MongoDB. - ⚙️ Configuration: Database settings are in
app/src/main/resources/META-INF/morphia-config.properties
, and the connection string is inapp/.env
.
Server-specific auto role settings are stored in MongoDB as follows:
- 🆔 Server ID
- 🔄 Auto role enabled/disabled status
- 🏷️ IDs of roles to assign