1. Create the Bot and Copy Its Token
In the Discord Developer Portal, create an application, open Bot, and reset the token to copy it. Treat the token like a password: anyone with it controls your bot. Turn on any privileged intents your bot needs, then invite it to your server from OAuth2 → URL Generator with the bot scope.
2. Prepare the Server
Order a VPS with Ubuntu 24.04, secure it, then create a user for the bot so it never runs as root:
sudo useradd -m -s /bin/bash bot sudo mkdir -p /home/bot/app && sudo chown bot:bot /home/bot/app
For a Node.js bot, install a current Node.js:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt install -y nodejs
For a Python bot, Ubuntu's Python is enough; add the virtual environment package:
sudo apt install -y python3-venv
3. Put the Code on the Server
Clone your repository into /home/bot/app as the bot user, or copy it up with rsync. Then install its dependencies:
sudo -u bot -i cd ~/app git clone https://github.com/you/your-bot.git . npm ci # Node.js # or, for Python: python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
A minimal bot to test with, in Node.js (discord.js) and Python (discord.py):
// index.js
import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once("ready", (c) => console.log(`Logged in as ${c.user.tag}`));
client.login(process.env.DISCORD_TOKEN);# bot.py
import os, discord
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print(f"Logged in as {client.user}")
client.run(os.environ["DISCORD_TOKEN"])4. Keep the Token Out of the Code
# /home/bot/app/.env (readable only by the bot user) DISCORD_TOKEN=paste-your-token-here
chmod 600 ~/app/.env echo ".env" >> ~/app/.gitignore
5. Run It as a Service
As a user with sudo, create /etc/systemd/system/discord-bot.service:
[Unit] Description=Discord bot After=network-online.target Wants=network-online.target [Service] User=bot WorkingDirectory=/home/bot/app EnvironmentFile=/home/bot/app/.env ExecStart=/usr/bin/node index.js # Python: ExecStart=/home/bot/app/.venv/bin/python bot.py Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable --now discord-bot journalctl -u discord-bot -f # "Logged in as ..." means it is online
Creating a systemd service explains each line. To update the bot, pull the new code as the bot user and run sudo systemctl restart discord-bot.
Running Several Bots
Give each bot its own folder and service file (discord-bot-music, discord-bot-mod and so on). Check memory with systemctl status on each; when the total nears the plan's memory, move to a larger plan from the dashboard. A bot with a database or a web dashboard can share the same server; see running Docker on a VPS if you prefer containers.