How to Host a Discord Bot on a VPS 24/7
Move your Discord bot off your laptop and onto a VPS so it stays online around the clock. Covers Node.js and Python, a process manager, and auto-restart.

Running your Discord bot from your laptop means it goes offline every time you close the lid. A VPS keeps it online 24/7 with a stable IP, auto-restart on crash, and start-on-boot. This guide covers the whole move — for Node.js or Python — and the good habits that keep a bot healthy.
Why a VPS beats your PC (and free tiers)
- Always on: no sleep, no reboots, no closed laptop.
- Auto-restart: a process manager or systemd restarts the bot if it crashes.
- Full control: install anything, run background jobs, scale up when your bot grows.
- No cold starts: unlike some free serverless tiers, a VPS runs your bot continuously.
A small 1 GB VPS comfortably runs several bots. See Discord bot hosting for plans, or how much RAM does a VPS need to size up.
Step 1: Basic server setup
Connect over SSH (how to connect to a VPS via SSH), then create a non-root user and update:
sudo adduser bot
sudo usermod -aG sudo bot
su - bot
sudo apt update && sudo apt upgrade -y
Lock the box down first with the basics in securing your first Linux VPS: 10 steps.
Step 2: Install your runtime
For a Node.js (discord.js) bot:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs git
node -v
For a Python (discord.py) bot:
sudo apt install -y python3 python3-venv python3-pip git
python3 --version
Step 3: Get your code onto the server
Clone from Git (recommended) or upload with scp:
git clone https://github.com/yourname/your-bot.git
cd your-bot
Install dependencies — npm install for Node, or a virtualenv + pip install -r requirements.txt for Python.

Step 4: Store the bot token safely
Never hard-code your token or commit it to Git. Put it in a .env file the bot reads at startup:
echo "DISCORD_TOKEN=your-bot-token-here" > .env
chmod 600 .env
If a token ever leaks, regenerate it immediately in the Discord Developer Portal.
Step 5: Keep it running with a process manager
The simplest robust option for Node is PM2, which restarts on crash and on reboot. We cover it in depth in how to keep a Discord bot online with PM2:
sudo npm install -g pm2
pm2 start index.js --name discord-bot
pm2 save
pm2 startup
For Python, either use PM2 (pm2 start bot.py --interpreter python3) or a systemd service — both are covered in how to host a Python Discord bot on a Linux VPS.
Step 6: Verify auto-restart
Reboot the server and confirm the bot comes back:
sudo reboot
# reconnect, then:
pm2 status
Your bot should be online in Discord within a minute of boot.
Good habits for a healthy bot
- Logs:
pm2 logs discord-bot(orjournalctl) to debug. - Updates:
git pull && npm install && pm2 restart discord-botto deploy changes. - Backups: keep your code in Git and back up any database or config.
- Isolation: run each bot as its own process/user so one crash doesn't take down the rest.
Want a container-based deploy instead? See how to deploy a Discord bot with Docker. Building a music bot? That has extra dependencies — see how to host a Discord music bot on a VPS.
Deploying updates cleanly
Treat your bot like any other app: keep the code in Git and deploy with a predictable sequence.
cd ~/your-bot
git pull
npm install # or: pip install -r requirements.txt
pm2 restart discord-bot # or: sudo systemctl restart discordbot
Tag releases in Git so you can roll back fast if an update misbehaves, and test changes on a second "staging" bot token before touching the live one.
Monitoring so it never silently dies
A bot that silently dies is worse than one that crashes loudly. Tail logs (pm2 logs or journalctl -u discordbot -f), and glance at resource use with the tools in how to monitor server resources on Linux. Set a memory cap so a leak restarts the process instead of taking down the whole box, and consider a simple uptime check that watches for the bot's "ready" log line. Running several bots? Give each its own folder and user, and see how to host multiple game servers on one VPS for the same isolation principles applied to any long-running service.
FAQ
How much does it cost to host a Discord bot on a VPS?
Not much — a small 1 GB VPS runs one or several lightweight bots and costs a few dollars a month. Music bots need more CPU and RAM.
Do I need Node.js or Python?
Whichever your bot is written in. discord.js is Node.js; discord.py is Python. Both host the same way — deploy code, set the token, use a process manager.
How do I keep the bot running after I log out?
Use a process manager (PM2) or a systemd service. Both detach the bot from your SSH session and restart it on crash or reboot.
Is it safe to store my token on a VPS?
Yes, if you keep it in a .env file with chmod 600, never commit it to Git, and secure the server with SSH keys and a firewall.
Get your bot online for good on Discord bot hosting from Nxeon — NVMe VPS, full root access, and free migration help if you're moving it from another host.