How to host a discord.js bot 24/7
Put a Node.js Discord bot online around the clock: a working example, the files to upload and how to start it.
A Discord bot only answers while its code is running. On your own computer it stops when you close the terminal or turn the PC off. Hosting runs it on a server instead, so it stays online 24/7 and is started again automatically if it crashes. This guide uses discord.js v14 on Node.js 22.
1. Create the bot in Discord
- Open the Discord Developer Portal and click New Application.
- Go to Bot and click Reset Token. Copy the token and keep it private — it's the bot's password.
- Under OAuth2 → URL Generator, tick bot (and applications.commands if you use slash commands), choose the permissions your bot needs and open the link to invite it to your server.
2. The code
Your project needs a package.json and a main file. The panel's default start command runs npm install and then node index.js.
{
"name": "my-bot",
"private": true,
"dependencies": {
"discord.js": "^14.16.0"
}
}const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.login(process.env.DISCORD_TOKEN);Don't write the token in index.js. The code reads it from the DISCORD_TOKEN variable, which you add in the panel.
3. Upload it
- Put package.json and index.js in a .zip. Leave out node_modules — it's installed on the server.
- In the panel, click a free slot, name the bot and choose Node.js 22.
- Open the Deploy tab and upload the .zip.
- Open the Environment tab and add DISCORD_TOKEN with your token.
4. Start it
Press Start and open the Console. You'll see npm installing discord.js and then "Logged in as …". Your bot is now online and stays online.
Common problems
- "An invalid token was provided" — the DISCORD_TOKEN value is wrong or was reset. Copy a new one from the Developer Portal.
- "Used disallowed intents" — enable the privileged intents you use (Message Content, Server Members) under Bot in the Developer Portal.
- "Cannot find module" — the file isn't called index.js or isn't at the top of the zip. Change the start command in Settings to match your file.