How to host a Discord bot on a VPS 24/7
How to host a Discord bot 24/7: use a small VPS plus a process manager: systemd for a Python (discord.py) bot or PM2 for a Node.js (discord.js) bot. The process manager restarts the bot after a crash and starts it again after a reboot, so you can close your terminal and shut down your PC. This guide covers Ubuntu 24.04, discord.py 2.7 and discord.js 14.
Prefer to delegate? Give this prompt to your AI agent:
Create an s1-1 server on 0x.cloud with the bots image and hourly billing. Show me the dry_run price and wait for my "yes". Deploy my Discord bot from <repository URL>, put the token in .env as DISCORD_TOKEN with 600 permissions, set up autostart with systemd for a Python bot or PM2 for a Node.js bot, and show me how to read the logs.
Requirements and plan
| Bot type | 0x.cloud plan | Price |
|---|---|---|
| Commands, moderation, alerts | s1-1: 1 vCPU, 1 GB RAM, 15 GB NVMe | $4.49/mo |
| Music (ffmpeg), AI replies, database | s1-2: 1 vCPU, 2 GB RAM, 30 GB NVMe | $7.99/mo |
| Several bots on one server | s2-4: 2 vCPU, 4 GB RAM | $15.99/mo |
For sizing, read how much RAM a bot needs. The 0x.cloud bots image already includes Python with Discord libraries, Node.js with PM2 and a service that keeps your bot running. On plain Ubuntu 24.04, follow the steps below.
Where those numbers come from: a bot without voice is a single Python or Node.js process holding one gateway connection. It uses tens of MB of RAM and next to no CPU, so 1 GB on s1-1 leaves plenty of room. A music bot transcodes audio through ffmpeg in real time, which keeps the CPU and memory busy, so give it s1-2. You can start on hourly billing: s1-1 is $0.030750 an hour ($4.49 / 730 × 5) and never more than $4.49 in a calendar month. Setup is $0.
Get your token in the Developer Portal: your application, Bot, Reset Token. Turn on Message Content Intent on the same page if the bot reads message text.
Prepare the server
Open the web console of the server in your cabinet (an agent runs the same commands with run_command) and update:
sudo apt update && sudo apt upgrade -y
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
A Discord bot opens an outbound connection to the Discord gateway, so it needs no inbound ports. Only SSH stays open: ufw status should list just OpenSSH ALLOW Anywhere (plus its IPv6 twin). See the UFW guide for more.
Option 1: Python bot (discord.py) with systemd
sudo apt install -y python3-venv git
mkdir ~/discord-bot && cd ~/discord-bot
python3 -m venv .venv
.venv/bin/pip install -U discord.py
Ubuntu 24.04 blocks pip installs into system Python, so everything goes into .venv. Check it with .venv/bin/python -c "import discord; print(discord.__version__)", which prints a version such as 2.7.1. For voice, install discord.py[voice] and sudo apt install -y ffmpeg.
bot.py:
import os
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
@bot.command()
async def ping(ctx):
await ctx.send("pong")
bot.run(os.environ["DISCORD_TOKEN"])
Store the token in a private .env:
echo 'DISCORD_TOKEN=your_token' > .env
chmod 600 .env
Create /etc/systemd/system/discord-bot.service (replace deploy with your user):
[Unit]
Description=Discord bot (discord.py)
After=network-online.target
Wants=network-online.target
[Service]
User=deploy
WorkingDirectory=/home/deploy/discord-bot
EnvironmentFile=/home/deploy/discord-bot/.env
Environment=PYTHONUNBUFFERED=1
ExecStart=/home/deploy/discord-bot/.venv/bin/python bot.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now discord-bot
journalctl -u discord-bot -f
enable --now turns on autostart and starts the bot, and journalctl -f follows the logs. Within seconds you should see Logged in as YourBot#0000 and the bot shows as online in Discord; type !ping in a channel and a pong reply confirms it works. PYTHONUNBUFFERED=1 makes print output reach the journal immediately instead of sitting in a buffer. RestartSec=10 adds a pause between restarts so a crash loop doesn't hammer the Discord API. All options are explained in how to create a systemd service.
Option 2: Node.js bot (discord.js) with PM2
Install Node.js 26 LTS from NodeSource, then PM2:
curl -fsSL https://deb.nodesource.com/setup_26.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
sudo npm install -g pm2
The script adds the NodeSource repository, apt install nodejs installs Node.js with npm, and the last line installs PM2 globally.
mkdir ~/discord-bot-js && cd ~/discord-bot-js
npm init -y && npm install discord.js
echo 'DISCORD_TOKEN=your_token' > .env && chmod 600 .env
index.js:
const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => {
console.log(`Ready as ${c.user.tag}`);
});
client.login(process.env.DISCORD_TOKEN);
Start it under PM2 and enable boot startup:
pm2 start index.js --name discord-bot --node-args="--env-file=.env"
pm2 startup
pm2 save
--env-file is built into Node.js and loads the token. pm2 startup prints a sudo command: copy and run it to register PM2 with systemd. pm2 save stores the process list that comes back after a reboot. Check with pm2 logs discord-bot --lines 20 (look for Ready as YourBot#0000) and pm2 status (status online). More PM2 detail is in deploy a Node.js app with PM2.
How to host a Discord bot 24/7: verify the restart
Reboot and check that the bot came back on its own:
sudo reboot
# after reconnecting
systemctl status discord-bot # Python
pm2 status # Node.js
Update the bot
cd ~/discord-bot && git pull
.venv/bin/pip install -U -r requirements.txt
sudo systemctl restart discord-bot
For Node.js: git pull, npm ci, then pm2 restart discord-bot. If you changed slash commands, re-register them with your command deploy script.
Back up the bot
Keep code in Git. Back up what only exists on the server, .env and data files:
tar czf ~/discord-bot-$(date +%F).tar.gz -C ~ discord-bot/.env discord-bot/data
Copy the archive off the server, for example with scp to another machine of yours. 0x.cloud also offers automatic backups (7 daily copies, +20% of the plan price) and $0.99/mo snapshots.
Troubleshooting
| Error | Fix |
|---|---|
PrivilegedIntentsRequired |
Enable the intent in the Developer Portal (Bot, Privileged Gateway Intents) |
LoginFailure: Improper token / TokenInvalid |
Token is wrong or was reset. Generate a new one and update .env |
Online but ! commands do nothing |
message_content is off in code or in the portal |
| Music bot has no sound | Install ffmpeg and discord.py[voice] |
| Offline after reboot | Missing systemctl enable, or pm2 startup + pm2 save |
| HTTP 429 or a temporary block | The bot is crash-looping. Fix the error in the logs and raise RestartSec |
Library reference: discord.py documentation. Need a server sized for bots with unmetered traffic up to 1 Gbps? See Discord bot hosting. Servers are in Warsaw, and support answers in about 30 minutes on average during business hours (06:00–20:00 UTC). Delete a server and billing stops at once, with the remainder back on your balance.
FAQ
Can I host a Discord bot 24/7 for free? Free platforms usually sleep idle apps or cap monthly hours. A VPS runs continuously. On 0x.cloud a simple bot fits on s1-1 at $4.49/mo, and hourly billing lets you pay by the hour.
systemd or PM2: which should I use? For a Python bot, systemd is simplest because it's already on Ubuntu. For discord.js, PM2 is handier: logs, restarts and a process list in one tool. Both bring the bot back after a reboot.
Why is my bot online but not reading messages? Message Content Intent is off. Enable it in the Developer Portal under Bot and in code with intents.message_content = True for discord.py.
How much RAM does a Discord bot need? A small discord.py or discord.js bot usually runs fine in 1 GB RAM. Music bots with ffmpeg and bots that call AI models are happier with 2 GB (s1-2).
Can I host a Discord bot on my own computer? Yes, but the bot is online only while your computer is on and connected. Sleep, a reboot or a dropped connection takes it offline. A server runs around the clock, and testing on s1-1 with hourly billing costs $0.030750 an hour.