Skip to content

Xjectro/java-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– java-discord-bot

A customizable Discord bot developed with Java.

✨ Features

  • πŸ“ Command-based structure
  • ⚑ Event listeners
  • 🧩 Easily extensible architecture
  • πŸ› οΈ Modern Java and Gradle usage

βš™οΈ Installation

πŸ“‹ Requirements

🚦 Steps

  1. πŸ“₯ Clone the repository:

git clone https://github.com/Xjectro/java-discord-bot.git cd java-discord-bot

2. πŸ“¦ Install dependencies and build:
   ```sh
./gradlew build
  1. πŸ” 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

4. πŸš€ Start the bot:
   ```sh
./gradlew run

πŸ•ΉοΈ Usage

After adding the bot to your server, you can use the following commands:

πŸ‘‘ Auto Role System

  • !autorole <enabled|disabled> [@role1 @role2 ...]
    • πŸ”„ Enables or disables the auto role system and sets the roles to assign.
    • πŸ’‘ Example: !autorole enabled @Member @Registered
  • You can also use it as a slash command:
    • /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 Command

  • !ping β€” Checks if the bot is running.

πŸ› οΈ Add Your Own Commands

  • πŸ—‚οΈ To add new commands, create a new class in the app/src/main/java/org/example/commands/ directory.

🀝 Contributing

Contributions are welcome! Please open an issue before submitting a pull request.

πŸ“„ License

This project is licensed under the MIT License.

πŸ“¬ Contact

πŸš€ Architecture & Technologies Used

  • β˜• 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.

πŸ—οΈ Architecture

  • πŸ“ 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 in app/.env.

πŸ—ƒοΈ Example Database Model

Server-specific auto role settings are stored in MongoDB as follows:

  • πŸ†” Server ID
  • πŸ”„ Auto role enabled/disabled status
  • 🏷️ IDs of roles to assign

πŸ“¦ Main Libraries Used