Create Your Own Custom Discord Bot Using Spring Boot
TL;DR: Most bots are written in TypeScript, but if you’re a Java developer, this Spring Boot 3 + JDA boilerplate helps you start building feature-rich Discord bots instantly.
Introduction
Most tutorials for Discord bots assume you’re using TypeScript. That’s fine if you live in the Node.js world, but what if your comfort zone is Java?
This boilerplate solves that gap. It provides a Spring Boot 3 + Java 21 starter kit for Discord bots, already wired with commands, listeners, and persistence.
Ideal for: Java developers, small teams, or anyone who prefers Spring’s ecosystem over Node.js.
Why this boilerplate?
- Saves time: You don’t have to wire up JDA, command parsing, or DB integration from scratch.
- Production-ready: Includes persistence, scheduled jobs, and modular architecture.
- Opinionated best practices: Clean package structure, DI with Spring, and JPA repositories.
- Includes: Command system, moderation tools, reminders, welcome listener, and MySQL integration.
Features
-
!ping
→ Health check -
!help
→ Built-in help menu -
!kick
,!ban
,!warn
→ Moderation commands -
!userinfo
,!serverinfo
→ Fetch server/user info -
!remind
→ Schedule personal reminders - Daily reminder job schedule reminders for server members
- Welcome listener for greeting new members
Roadmap ideas: dashboard integration, role-based access, Docker Compose setup.
Prerequisites
- Java 21 / OpenJDK 21
- Maven 3.8+
- MySQL or Postgres (for persistence)
- Docker (optional, for containerized deployment)
Quick Start (Install & Run)
Setup on local
- Download the zip from Discord Bot Boilerplate (Spring Boot + JDA) and extract.
- Open it with your IDE (IntelliJ, Eclipse, VS Code).
- Add your Discord bot token to
application.properties
. - Build and run:
./mvnw spring-boot:run
Or package into a JAR:
./mvnw clean package -DskipTests
java -jar target/discord-bot-1.0.jar
Usage & Examples
Simple command
Inside Discord, try:
!ping
Response:
Pong!
Reminder example
!reminder 13:15 Take a break
Bot replies:
Got it! I’ll remind you in 10 minutes.
Configuration
In src/main/resources/application.properties
:
discord.bot.token=YOUR_DISCORD_BOT_TOKEN
discord.bot.prefix=!
spring.datasource.url=jdbc:mysql://localhost:3306/discordbot
spring.datasource.username=root
spring.datasource.password=secret
Environment variables (if using Docker):
-
DISCORD_BOT_TOKEN
— your bot token -
DATABASE_URL
— DB connection -
SPRING_PROFILES_ACTIVE
— profile (dev
,prod
)
Project Structure
discord-bot/
├── pom.xml
├── src/main/java/com/discordbot
│ ├── command/impl/ # PingCommand, HelpCommand, KickCommand, etc.
│ ├── config/ # Spring + JDA config
│ ├── entities/ # GuildSettings, Reminder, UserPreference
│ ├── jobs/ # ReminderScheduler, DailyReminder
│ ├── listener/ # BotListener, WelcomeListener
│ └── repositories/ # JPA repositories
└── src/main/resources/application.properties
Testing
Run unit tests:
./mvnw test
Integration tests can be added with Spring Boot Test + Testcontainers if you’re running a DB in Docker.
Deployment
- Build the JAR and run on any VPS or cloud instance.
- Or create a Docker image:
FROM eclipse-temurin:21-jdk-alpine
WORKDIR /app
COPY target/discord-bot-1.0.jar app.jar
ENTRYPOINT ["java","-jar","/app/app.jar"]
- Deploy via Docker Compose or a CI/CD pipeline.
Extending & Customization
-
Add new commands: create a new class under
command/impl/
. -
Add entities: extend the
entities/
package and define a repository. -
New event listeners: add to
listener/
and wire up in the config.
Troubleshooting / FAQ
-
Bot won’t start → Check if
discord.bot.token
is set correctly. -
Database errors → Verify
spring.datasource.*
configs. - Commands not responding → Make sure the bot has the right permissions in your Discord server.
License
This project is under the MIT License. See the LICENSE.md
file for details.
About Boileragents
Boileragents builds practical, ready-to-use boilerplates so you can skip the boring setup and start coding.
GitHub: https://github.com/boileragents
Email: boileragents@gmail.com
If this boilerplate saved you time, give it a ⭐ on GitHub and share your feedback.
Need a custom feature? Reach out at boileragents@gmail.com
.
Top comments (0)