Tutorial Spring Boot Discord Bots

How to Build and Deploy a Java Discord Bot Using Spring Boot

Published: March 21, 2026 Updated: May 18, 2026 12 min read

This guide walks through setting up a Discord application, configuring your bot token, running the project locally, and deploying it on a VPS. The example uses Basely, a clean Java starter for Discord bot development.

Quick answer

To build a Java Discord bot with Spring Boot, create a Discord application, generate a bot token, configure your environment variables, run the bot locally with JDA, and deploy it on a VPS for production. Using a starter boilerplate like Basely makes setup significantly faster.

Discord bots are one of the easiest ways to automate community tasks, build moderation tools, create reminder systems, and add custom workflows to Discord servers. For Java developers, the hard part is usually not the bot logic itself. It is the repetitive setup around authentication, command structure, project wiring, and deployment.

That is where Basely fits in. It gives you a practical Spring Boot foundation for a Discord bot so you can focus on the actual features instead of rebuilding the same base every time.

What Basely is for

Basely is a Java Discord bot boilerplate designed for developers who want a clean starting point. It is useful for moderation bots, utility bots, reminder bots, community assistants, and learning projects built with JDA and Spring Boot.

The idea is simple: instead of starting with an empty project and deciding everything from scratch, you begin with a structured codebase that already has a clear path for commands, events, services, and configuration.

Before you start

  • Java 21 or newer
  • Maven installed locally, or the Maven wrapper included in the project
  • A Discord account
  • Access to the Discord Developer Portal
  • A VPS with Java installed for production deployment

1. Create your Discord application

Start by opening the Discord Developer Portal. From there, create a new application and give it a name that matches your bot.

Once the application exists, open the Bot tab and click Add Bot. Discord will create the bot user attached to your application.

Copy the bot token carefully. This token is the secret key your application uses to authenticate with Discord. Never commit it to GitHub and never paste it directly into public files.

Recommended settings in the Developer Portal

  • Enable the bot user under the Bot tab
  • Copy the token and store it securely
  • Turn on only the privileged intents you actually need
  • Keep the application name and avatar consistent with your project brand

2. Invite the bot to your server

To test the bot locally, invite it to a Discord server where you have permission to manage integrations. Use the OAuth2 URL generator inside the Discord Developer Portal.

Select the bot scope and, if your project uses slash commands, also select applications.commands. Then choose the permissions your bot needs. For a test server, start with the minimum required permissions and expand later.

After generating the invite link, open it in your browser and add the bot to the server.

3. Configure Basely locally

Grab the project from here →

Then configure the environment variables your Spring Boot Discord bot needs. The exact variable names depend on your code, but a clean setup usually looks like this:

spring.application.name=Basely
server.port=8080

discord.token=${DISCORD_BOT_TOKEN}
discord.guild-id=${DISCORD_GUILD_ID}

Adjust these names to match your implementation if your project uses a different configuration style.

4. Run the project locally

Run the project as a Spring Boot application from your IDE. If your Discord bot token is configured correctly, the bot should connect immediately.

If the bot logs in successfully, you should see it connect to Discord and register the configured commands or listeners.

5. Prepare the VPS

For production deployment, run your Java Discord bot on a VPS instead of your local machine. This keeps the bot online continuously and provides a stable runtime environment for long-running background processes.

Make sure docker compose is installed on your VPS.

docker compose version
          

If not then install docker + docker compose.

sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo $VERSION_CODENAME) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update

sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin

sudo systemctl start docker
sudo systemctl enable docker

sudo usermod -aG docker $USER
newgrp docker
          

6. Run Bot with docker container

On the VPS, create docker-compose.yml file:

version: "3.9"

services:
    mysql:
    image: mysql:8.0
    container_name: basely-mysql
    restart: always

    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: boiler_agent_discord_bot_db

    volumes:
      - mysql_data:/var/lib/mysql

    ports:
      - "3306:3306"

  basely:
    image: eclipse-temurin:21-jdk
    container_name: basely-bot
    restart: always

    depends_on:
      - mysql

    working_dir: /app

    volumes:
      - ./basely.jar:/app/basely.jar

    env_file:
      - .env

    command: ["java", "-jar", "/app/basely.jar"]

    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/boiler_agent_discord_bot_db
      SPRING_DATASOURCE_USERNAME: root
      SPRING_DATASOURCE_PASSWORD: rootpassword

    logging:
      options:
        max-size: "10m"
        max-file: "3"

volumes:
  mysql_data:

and .env file like this:

DISCORD_TOKEN=your_discord_bot_token_here
SPRING_PROFILES_ACTIVE=prod
            

Run basely with docker compose

docker compose up -d
            

Common issues

Bot stays offline

Check whether the token is correct, whether the service is running, and whether the bot has permission to connect. A wrong environment variable name is a common cause.

Slash commands do not appear

Make sure the bot was invited with the applications.commands scope and that your registration code is running at startup.

Service exits immediately

Inspect the logs. Usually the issue is a missing environment file, incorrect jar path, or a startup exception from the application itself.

Frequently asked questions

What is the best Java library for building Discord bots?

JDA (Java Discord API) is one of the most widely used libraries for building Discord bots in Java. It provides support for slash commands, event listeners, messaging, and Discord API integration.

Can I build a Discord bot with Spring Boot?

Yes. Spring Boot works well for Discord bot development, especially when you want clean dependency management, configuration handling, database integration, scheduled jobs, and production-ready project structure.

How do I deploy a Java Discord bot?

A Java Discord bot can be deployed on a VPS using Docker or by running the packaged JAR directly. Production deployment should keep the bot online continuously and securely manage environment variables like the Discord token.

Is building a Discord bot from scratch worth it?

It depends on your goal. For learning, building from scratch helps you understand architecture and Discord APIs. For shipping faster, starting with a structured boilerplate saves significant setup time.

What permissions does a Discord bot need?

Only grant the permissions your bot actually needs. Common permissions include sending messages, reading message history, managing roles, or using slash commands depending on your bot features.

Final thoughts

A Discord bot becomes much easier to ship when the base structure is already in place. Instead of wiring authentication, command handling, configuration, and deployment from scratch, you can start with Basely and focus on building actual bot features.

Want to skip Discord bot setup from scratch?

Basely gives you a clean Java Discord bot foundation built with Spring Boot and JDA. Skip repetitive setup like project structure, command wiring, configuration, and deployment groundwork.

Explore Basely

Related BuildBaseKit Foundation

Apply the ideas in this guide with a focused Java Discord bot starter kit, or learn how BuildBaseKit approaches a modular Java backend foundation.

Related articles

Guide Java JDA 5 min read

Discord Bot Structure in Java (JDA Guide)

Most Discord bots become messy fast. Learn a clean JDA structure with proper separation of commands, events, and services that actually scales.