How to Host a Discord Bot on VPS: Complete Setup Guide 2026
Deploy your Discord bot to a VPS and keep it online 24/7. Step-by-step guide covering Node.js, Python, PM2, systemd, and Docker deployment.
How to Host a Discord Bot on VPS: Keep It Online 24/7
Running your Discord bot on your laptop means it dies when you close the lid. A VPS gives your bot a permanent home — always online, always responding, for as little as $2/month.
This guide covers deploying Node.js and Python bots with three methods: PM2, systemd, and Docker. Pick whichever fits your workflow.
What You’ll Set Up
What You'll Set Up
- ✅ Discord bot running 24/7 on a VPS
- ✅ Auto-restart on crashes
- ✅ Auto-start on server reboot
- ✅ Log management
- ✅ Environment variable security
Time required: 15-20 minutes
Prerequisites
- A working Discord bot (locally tested)
- A Discord bot token from the Developer Portal
- Basic terminal/SSH knowledge
- A VPS (see recommendations below)
VPS Requirements
Discord bots are lightweight. Unless you’re doing heavy processing (AI, image generation, music streaming), minimal specs work fine:
- CPU: 1 vCPU
- RAM: 512MB–1GB (most bots use under 100MB)
- Storage: 10GB+
- OS: Ubuntu 22.04+ or Debian 12+
Recommended VPS Providers
| Provider | Plan | Specs | Price | Best For |
|---|---|---|---|---|
| Hostinger | KVM1 | 1 vCPU, 4GB RAM | $4.99/mo | Best overall value |
| Hetzner | CX22 | 2 vCPU, 4GB RAM | €3.79/mo | European hosting |
| Contabo | VPS S | 4 vCPU, 8GB RAM | €5.99/mo | Max resources per dollar |
For a detailed breakdown, see our Best VPS for Discord Bot guide.
Step 1: Initial Server Setup
SSH into your fresh VPS:
ssh root@your-server-ip
Update the system and create a non-root user:
# Update packages
apt update && apt upgrade -y
# Create a dedicated user for the bot
adduser botuser
usermod -aG sudo botuser
# Switch to the new user
su - botuser
Security tip: Never run bots as root. A compromised bot with root access means a compromised server.
Step 2: Install Your Runtime
For Node.js Bots
Install Node.js via nvm (Node Version Manager):
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash
source ~/.bashrc
# Install latest LTS
nvm install --lts
node --version # Should show v22.x or newer
For Python Bots
# Install Python and pip
sudo apt install python3 python3-pip python3-venv -y
python3 --version # Should show 3.11+
Step 3: Upload Your Bot Code
You have several options:
Option A: Git Clone (Recommended)
cd ~
git clone https://github.com/yourusername/your-discord-bot.git
cd your-discord-bot
Option B: SCP from Your Machine
# Run this from your LOCAL machine
scp -r ./my-bot botuser@your-server-ip:~/my-bot
Option C: SFTP
Use FileZilla or any SFTP client to drag-and-drop your files.
Step 4: Install Dependencies
cd ~/your-discord-bot
# Node.js
npm install
# Python
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Step 5: Set Up Environment Variables
Never hardcode your bot token. Use a .env file:
# Create .env file
nano .env
Add your secrets:
DISCORD_TOKEN=your-bot-token-here
PREFIX=!
DATABASE_URL=sqlite:///bot.db
Lock down permissions:
chmod 600 .env
For Node.js, use the dotenv package:
// At the top of your main file
require('dotenv').config();
const token = process.env.DISCORD_TOKEN;
For Python, use python-dotenv:
from dotenv import load_dotenv
import os
load_dotenv()
token = os.getenv("DISCORD_TOKEN")
Step 6: Test the Bot
Before setting up auto-restart, verify it runs:
# Node.js
node index.js
# Python
python3 bot.py
You should see your bot come online in Discord. Press Ctrl+C to stop it.
Deploying Your Bot
Deploying Your Bot
Now the important part — keeping it running permanently. Choose one method:
Method 1: PM2 (Node.js — Easiest)
PM2 is a process manager built for Node.js. It handles restarts, logs, and monitoring out of the box.
# Install PM2 globally
npm install -g pm2
# Start your bot
pm2 start index.js --name "discord-bot"
# Auto-start on server reboot
pm2 startup
pm2 save
Useful PM2 Commands
pm2 status # Check bot status
pm2 logs discord-bot # View live logs
pm2 restart discord-bot # Restart the bot
pm2 stop discord-bot # Stop the bot
pm2 monit # Real-time monitoring dashboard
PM2 with Environment Variables
pm2 start index.js --name "discord-bot" --env production
Or create an ecosystem.config.js:
module.exports = {
apps: [{
name: "discord-bot",
script: "index.js",
env: {
NODE_ENV: "production",
},
max_memory_restart: "200M",
error_file: "./logs/error.log",
out_file: "./logs/output.log",
}]
};
Then run:
pm2 start ecosystem.config.js
pm2 save
Method 2: systemd (Any Language)
systemd works with any language and is built into every modern Linux distro.
Create a service file:
sudo nano /etc/systemd/system/discord-bot.service
For Node.js:
[Unit]
Description=Discord Bot
After=network.target
[Service]
Type=simple
User=botuser
WorkingDirectory=/home/botuser/your-discord-bot
ExecStart=/home/botuser/.nvm/versions/node/v22.14.0/bin/node index.js
Restart=always
RestartSec=5
EnvironmentFile=/home/botuser/your-discord-bot/.env
[Install]
WantedBy=multi-user.target
For Python:
[Unit]
Description=Discord Bot
After=network.target
[Service]
Type=simple
User=botuser
WorkingDirectory=/home/botuser/your-discord-bot
ExecStart=/home/botuser/your-discord-bot/venv/bin/python3 bot.py
Restart=always
RestartSec=5
EnvironmentFile=/home/botuser/your-discord-bot/.env
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable discord-bot
sudo systemctl start discord-bot
Useful systemd Commands
sudo systemctl status discord-bot # Check status
sudo journalctl -u discord-bot -f # View live logs
sudo systemctl restart discord-bot # Restart
sudo systemctl stop discord-bot # Stop
Method 3: Docker (Best for Production)
Docker isolates your bot and makes deployments reproducible.
Dockerfile for Node.js:
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["node", "index.js"]
Dockerfile for Python:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "bot.py"]
docker-compose.yml:
services:
discord-bot:
build: .
restart: always
env_file:
- .env
volumes:
- ./data:/app/data
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
Deploy:
docker compose up -d
Useful Docker Commands
docker compose logs -f # View live logs
docker compose restart # Restart
docker compose down # Stop
docker compose up -d --build # Rebuild and restart
Updating Your Bot
With Git + PM2
cd ~/your-discord-bot
git pull
npm install
pm2 restart discord-bot
With Git + systemd
cd ~/your-discord-bot
git pull
npm install # or pip install -r requirements.txt
sudo systemctl restart discord-bot
With Docker
cd ~/your-discord-bot
git pull
docker compose up -d --build
Monitoring and Logs
Keep an eye on your bot:
Check Resource Usage
# General system resources
htop
# PM2 monitoring
pm2 monit
# Docker stats
docker stats
Log Rotation (systemd)
systemd handles log rotation automatically via journalctl. To limit log size:
sudo nano /etc/systemd/journald.conf
# Set: SystemMaxUse=500M
sudo systemctl restart systemd-journald
Troubleshooting
Bot Goes Offline After SSH Disconnect
You’re running the bot in a regular terminal session. Use PM2, systemd, or Docker — they run independently of your SSH session.
”Error: Cannot find module”
Dependencies aren’t installed:
npm install # Node.js
pip install -r requirements.txt # Python
Bot Crashes in a Loop
Check the logs:
pm2 logs discord-bot --lines 50
# or
sudo journalctl -u discord-bot --lines 50
# or
docker compose logs --tail 50
Common causes: invalid token, missing intents, rate limiting.
”Error: Used disallowed intents”
Enable required intents in the Discord Developer Portal → Bot → Privileged Gateway Intents.
High Memory Usage
If your bot leaks memory:
# PM2: auto-restart at 200MB
pm2 start index.js --max-memory-restart 200M
# Docker: set memory limit
# In docker-compose.yml:
# deploy:
# resources:
# limits:
# memory: 256M
Security Best Practices
- Never commit
.envfiles — Add.envto.gitignore - Use a dedicated user — Don’t run as root
- Keep your system updated —
sudo apt update && sudo apt upgrade - Set up a firewall — Only allow SSH (port 22) and any ports your bot needs:
sudo ufw allow OpenSSH
sudo ufw enable
- Use SSH keys — Disable password authentication for extra security. See our SSH key management guide
- Rotate your bot token — If you suspect a leak, regenerate it immediately in the Developer Portal
Which Method Should You Choose?
| Method | Best For | Pros | Cons |
|---|---|---|---|
| PM2 | Node.js bots, beginners | Easy setup, great monitoring | Node.js only |
| systemd | Any language, single bot | No extra software, built-in | More config needed |
| Docker | Production, multiple bots | Isolated, reproducible | More disk usage |
Our recommendation: Start with PM2 if you’re running a Node.js bot. Move to Docker when you’re running multiple services or want reproducible deployments.
What’s Next?
- Add a database — Set up PostgreSQL or SQLite for persistent data
- Set up monitoring — Use Uptime Kuma to get notified if your bot goes down
- Secure your server — Follow our VPS security guide
- Scale up — Running multiple bots? Check our Docker Compose guide
Need a VPS for your Discord bot? Hostinger offers reliable hosting from $4.99/mo with 24/7 uptime — perfect for keeping your bot online.
Ready to get started?
Get the best VPS hosting deal today. Hostinger offers 4GB RAM VPS starting at just $4.99/mo.
Get Hostinger VPS — $4.99/mo// up to 75% off + free domain included
// related topics
// related guides
Best VPS for Discord Bot Hosting 2026: Keep Your Bot Online 24/7
Need to host your Discord bot on a VPS? We tested the top providers to find the best options for reliable, affordable bot hosting.
tutorial$1 VPS Hosting 2026: Cheapest VPS Servers Starting at $1/Month
Looking for $1 VPS hosting? Compare the cheapest VPS providers starting from $1-3/month. Real specs, no hidden fees, honest reviews of budget VPS options.
tutorialCaddy Reverse Proxy Guide 2026: Automatic HTTPS Made Easy
Set up Caddy as a reverse proxy with automatic HTTPS, zero-config SSL, and simple Caddyfile syntax. Complete VPS deployment guide.
tutorialCloudflare Tunnel VPS Guide 2026: Expose Services Without Opening Ports
Set up Cloudflare Tunnel on your VPS to expose web apps securely without opening ports or revealing your server IP. Complete guide with Docker and DNS config.
Andrius Putna
I am Andrius Putna. Geek. Since early 2000 in love tinkering with web technologies. Now AI. Bridging business and technology to drive meaningful impact. Combining expertise in customer experience, technology, and business strategy to deliver valuable insights. Father, open-source contributor, investor, 2xIronman, MBA graduate.
// last updated: March 25, 2026. Disclosure: This article may contain affiliate links.