Docs · Discord bots

Host a discord.js bot (JavaScript or TypeScript)

Run a discord.js bot 24/7 in JavaScript or TypeScript, with Node.js or Bun. Packages from package.json install on every start.

Startup → Docker Image → Node.js 24 (or Bun). Then upload these files.

The files

package.json lists your packages:

{
  "name": "my-bot",
  "main": "index.js",
  "dependencies": {
    "discord.js": "^14.16.0",
    "dotenv": "^16.4.5"
  }
}

index.js is the bot:

require('dotenv').config();
const { Client, Events, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => console.log(`Logged in as ${c.user.tag}`));
client.login(process.env.DISCORD_TOKEN);

.env holds the token: DISCORD_TOKEN=your-token-here.

Don’t upload node_modules. On start we run npm install (or pnpm / yarn when you have their lock file), then start your bot.

How we start it

  1. Main file in the Startup tab, if you set one.
  2. Otherwise your start script from package.json (npm start).
  3. Otherwise main from package.json, or the first of index.js, bot.js, main.js, src/index.js.

TypeScript

Three ways, pick one:

  • Set Main file to index.ts (or name it index.ts). It runs with tsx, no build step.
  • Have a build script (like tsc) and a start script (like node dist/index.js) in package.json: we run npm run build, then npm start.
  • Pick Bun: it runs .ts files directly and reads .env by itself (no dotenv needed).

Good to know

  • Message content: to read messages, add GatewayIntentBits.GuildMessages and GatewayIntentBits.MessageContent, and switch on Message Content Intent in the Developer Portal → your app → Bot.
  • Slash commands register with a separate script (often deploy-commands.js). Run it once from your computer, or set Own start command to node deploy-commands.js && node index.js.
  • Music bots need ffmpeg. It’s already installed.
  • Stop sends Ctrl+C: listen for process.on('SIGINT', …) to save data before the bot closes.

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.