An open API service indexing awesome lists of open source software.

https://github.com/xjectro/java-discord-bot

🤖 A customizable Discord bot developed with Java.
https://github.com/xjectro/java-discord-bot

boilerplate bot bots discord discord-api discord-app discord-bot discord-bot-template discord-java discordbot discordjava example gradle java java-8 jda mongodb sharding starter template

Last synced: 11 days ago
JSON representation

🤖 A customizable Discord bot developed with Java.

Awesome Lists containing this project

README

          

# 🤖 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
- ☕ Java 17 or higher
- đŸ› ī¸ [Gradle](https://gradle.org/) (or local setup with `gradlew`)
- 🔑 A Discord bot token ([Discord Developer Portal](https://discord.com/developers/applications))

### đŸšĻ Steps
1. đŸ“Ĩ Clone the repository:
```sh
git clone https://github.com/Xjectro/java-discord-bot.git
cd java-discord-bot

2. đŸ“Ļ Install dependencies and build:

```sh
./gradlew build
```

3. 🔐 Add your bot token and (optionally) database connection string to the `app/.env` file. Example:

```env
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 [@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: 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](LICENSE).

## đŸ“Ŧ Contact

* 👤 Developer: [Xjectro](https://github.com/Xjectro)
* 👤 Developer2: [range79](https://github.com/range79)
* 🔗 Project Link: [github.com/Xjectro/java-discord-bot](https://github.com/Xjectro/java-discord-bot)

## 🚀 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

* [🤖 JDA](https://github.com/DV8FromTheWorld/JDA)
* [đŸŸĸ Morphia](https://morphia.dev/)
* [đŸ—ī¸ dotenv-java](https://github.com/cdimascio/dotenv-java)
* [🍃 MongoDB Java Driver](https://mongodb.github.io/mongo-java-driver/)