Guides

Discord bots

Bots are long-running processes that connect out to Discord. They don't need a web address, so Vorl runs them as always-on services and restarts them if they crash.

1. Prepare the repo

Your bot should read its token from an environment variable instead of the code:

python
import os
import discord

client = discord.Client(intents=discord.Intents.default())
client.run(os.environ["DISCORD_TOKEN"])
js
import { Client, GatewayIntentBits } from 'discord.js';

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.login(process.env.DISCORD_TOKEN);

Commit a requirements.txt (Python) or package.json (Node) so the build knows what to install.

2. Deploy it

Create a project, choose GitHub Repository, and pick the bot's repo. Or start from the Discord bot template.

3. Add the token

Open the service → Variables → New Variable. Add DISCORD_TOKEN with the token from the Discord Developer Portal. Then click Deploy on the bar that appears.

Warning Never commit your bot token. If it ever ends up on GitHub, reset it in the Developer Portal right away.

4. Check it's online

The Deployments tab shows the build and start log. Your bot's own print or console.log output appears there too.

Giving it a database

Add Postgres to the same project and set DATABASE_URL=${{Postgres.DATABASE_URL}} on the bot. See Databases.

Start command

If your entry file isn't detected, set it in Settings → Deploy → Start command, for example python bot.py or node index.js.