Docs · Discord bots

Host a Java Discord bot (JDA)

Build your JDA or Javacord bot into one .jar on your computer, upload it and press Start. The token stays in a .env file.

Startup → Docker Image → Java 21 (or the version your project uses). Java bots run from one .jar file that you build on your computer.

1. Build one .jar with everything inside

A normal build leaves the libraries out, and the bot can’t start. Build a “fat” jar:

  • Gradle: add the Shadow plugin (com.gradleup.shadow) and run ./gradlew shadowJar. Your file is in build/libs/, ending in -all.jar.
  • Maven: add the maven-shade-plugin and run mvn package. Your file is in target/.

2. Read the token from .env

Java doesn’t read .env by itself. Add the small dotenv-java library (io.github.cdimascio:dotenv-java):

import io.github.cdimascio.dotenv.Dotenv;
import net.dv8tion.jda.api.JDABuilder;

public class Bot {
    public static void main(String[] args) throws Exception {
        String token = Dotenv.load().get("DISCORD_TOKEN");
        JDABuilder.createDefault(token).build().awaitReady();
        System.out.println("Logged in");
    }
}

Then make a .env file on the server: DISCORD_TOKEN=your-token-here.

3. Upload and start

Upload the .jar (and .env) to the main folder and press Start. With one .jar we start it by ourselves. With more than one, type the right one in Main file.

Good to know

  • Memory: the bot may use up to 90% of your plan’s RAM, so it never runs out before the server does.
  • Message content: add GatewayIntent.MESSAGE_CONTENT in JDABuilder and switch on Message Content Intent in the Developer Portal → your app → Bot.
  • After a change, build again and upload the new .jar over the old one.

More help: Run your Discord bot 24/7.

Still stuck?

Open a ticket with your service name and the console error, and a real person helps you.