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 inbuild/libs/, ending in-all.jar. - Maven: add the
maven-shade-pluginand runmvn package. Your file is intarget/.
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_CONTENTinJDABuilderand switch on Message Content Intent in the Developer Portal → your app → Bot. - After a change, build again and upload the new
.jarover the old one.
More help: Run your Discord bot 24/7.