TutorialNov 7, 20264 min read

How to Host a Discord Bot 24/7 on a VPS

Keep a discord.py or discord.js bot online around the clock on a small Linux VPS: which size, the intents to switch on, a systemd service that restarts it, and how to keep the token safe.

Short answer: run the bot on a small Linux VPS as a systemd service. A Discord bot opens its own connection to Discord's gateway, so it needs no domain, no certificate and no open port. A server with 1 vCPU and 1 GB RAM for $3.90 a month runs most bots; music bots and bots in thousands of servers want 2 GB or more.

Your PC can't stay on forever, and free hosts put bots to sleep or cap their hours. A VPS keeps the bot online with a fixed IP, your own files and the language version you choose.

01Which Server

BotPlanPrice
Moderation, commands, a few servers1 vCPU, 1 GB RAM, 10 GB NVMe$3.90/month
Music bot, a database, or several bots1–2 vCPU, 2 GB RAM, 20 GB NVMe$6.50/month
Large bots, AI features, image work2 vCPU, 6 GB RAM, 40 GB NVMe$13/month

For voice and music, pick a location near most of your users: Amsterdam or Frankfurt for Europe, New York for the Americas, Hong Kong for Asia.

Nano1 vCPU · 1 GB · 10 GB NVMe$3.90/mobilled monthlyBuy
Most popularSpark1 vCPU · 2 GB · 20 GB NVMe$6.50/mobilled monthlyBuy
Pulse2 vCPU · 2 GB · 20 GB NVMe$6.50/mobilled monthlyBuy
Surge2 vCPU · 6 GB · 40 GB NVMe$13.00/mobilled monthlyBuy
Storm6 vCPU · 10 GB · 40 GB NVMe$26.00/mobilled monthlyBuy
Apex6 vCPU · 10 GB · 80 GB NVMe$39.00/mobilled monthlyBuy

Full root SSH access · NVMe storage · DDoS protection · No setup fee

02Before You Deploy: Intents

In the Discord Developer Portal, open your application, go to Bot and switch on the privileged intents your code asks for:

  • Message Content if the bot reads what people write (prefix commands like !play)
  • Server Members if it reacts to joins or reads the member list
  • Presence only if it really needs online status

If the code requests a privileged intent that's switched off in the portal, Discord refuses the connection (discord.py raises PrivilegedIntentsRequired). If it's on in the portal but not requested in the code, the bot connects but message text arrives empty. Slash commands don't need Message Content.

03Put the Bot on the Server

On Ubuntu 24.04 or Debian 12, logged in over SSH as root:

  1. 1Create a user: adduser --disabled-password --gecos "" bot
  2. 2Install the runtime: apt update && apt install -y python3-venv git for discord.py, or apt install -y nodejs npm for discord.js (or Node from NodeSource for a newer version).
  3. 3Music bots only: apt install -y ffmpeg
  4. 4Copy your code as the bot user (su - bot) with git clone or scp, and install dependencies: python3 -m venv .venv && .venv/bin/pip install -r requirements.txt, or npm ci.
  5. 5Store the token in /home/bot/bot.env as DISCORD_TOKEN=..., then chmod 600 bot.env.
  6. 6Test it once: set -a; . ./bot.env; .venv/bin/python bot.py and check the bot shows online in Discord.

04Run It as a Service

Create /etc/systemd/system/discord-bot.service:

ini
[Unit]
Description=Discord bot
After=network-online.target
Wants=network-online.target

[Service]
User=bot
WorkingDirectory=/home/bot/mybot
EnvironmentFile=/home/bot/bot.env
ExecStart=/home/bot/mybot/.venv/bin/python bot.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

For discord.js use ExecStart=/usr/bin/node index.js. Then:

bash
systemctl daemon-reload
systemctl enable --now discord-bot
journalctl -u discord-bot -f

Restart=always brings the bot back after a crash; RestartSec=10 keeps it from hammering Discord's login if something is wrong.

05Keep It Healthy

Never commit the token

If it leaks, press Reset Token in the Developer Portal; the old one stops working at once.

Don't run two copies with the same token

Both get every event and answer twice.

Watch memory

with free -h and htop. Music queues and big caches grow; move up a size if the server starts swapping.

Update dependencies

now and then: Discord changes its API, and old library versions stop working.

06Keep the Server Safe

  • SSH only from your IP with the firewall on your server page, and log in with a key.
  • Automatic security updates: apt install -y unattended-upgrades.
  • Back up the bot's database off the server; we don't make backups for you.

From $3.90 a month for 1 vCPU, 1 GB RAM and 10 GB NVMe, which is enough for most bots.

  • host discord bot
  • discord bot hosting
  • run discord bot 24/7
  • discord bot vps
  • discord.py hosting
  • discord.js hosting

Keep reading

All articles