Hosting a Discord Bot 24/7 on a VPS in 2026: Complete Guide (Node/Python, systemd, Docker)
2026 technical guide for hosting a Discord bot continuously on a VPS. Compare Node vs Python, systemd vs Docker, sizing, costs, and token security for developers.
Building a high-performance Discord bot is one thing; keeping it online 24/7 is another. Too many beginner developers fall into the trap of free hosting (Heroku, Render, Railway) or their own personal PC, only to discover that the service cuts out during updates, the PC shuts down, or response times increase drastically. In 2026, the ecosystem has matured: on-demand VPS instances are cheaper than ever, and process management tools are robust.
This guide doesn’t sell dreams. It gives you the exact technical recipes to deploy your bot industrially, securely, and economically. We will compare stacks (Node.js vs Python), choose the right VPS, install dependencies, configure automatic restarts via systemd or Docker, and secure your OAuth2 token.
Why a VPS? A cold analysis of alternatives
Before touching a single line of code, you need to understand why infrastructure matters so much. A Discord bot is not a simple static web page. It is a long-running process that maintains an open WebSocket connection to Discord’s servers. If the process dies, the connection is lost, and the bot disappears from the member list.
The Myth of the “Personal PC”
Hosting on your personal machine seems free. In reality, it incurs hidden costs in energy, hardware wear, and bandwidth. Furthermore, your home connection often has a dynamic IP and variable latency. If your internet cuts out for 10 minutes, your bot goes offline. For a serious community, this is unacceptable.
The Illusion of Free Hosting (PaaS)
Platforms like Heroku or Render offer quick startups. However, in 2026, most “free tier” offers have either disappeared or introduced “spin-down” (the server goes to sleep after 15 minutes of inactivity). For a bot, this means waiting 30 to 60 seconds for the first interaction after a quiet period. This is a disastrous user experience (UX). Moreover, these services often limit RAM and logs, making debugging difficult.
The VPS Solution: Total Control
A VPS (Virtual Private Server) gives you root access to a dedicated Linux machine. You pay for guaranteed resources (RAM, CPU), a fixed IP, and 99.9% availability. For a Discord bot, you don’t need a physical dedicated server. A lightweight cloud VPS is more than enough.
Sizing: How many resources does a bot need?
Many beginners over-provision. A standard Discord bot, even with complex features (moderation, light music, lightweight databases), is very resource-efficient compared to a dynamic website or a game.
Resource Benchmark
Here are the actual consumptions observed in 2026 for a functional bot:
- RAM: 50 to 150 MB for a simple bot in Node.js or Python. Even with 10,000 members in the main server, memory load remains stable as long as you don’t load the entire message history into RAM.
- CPU: < 1% at idle. Calculation spikes (e.g., image generation, LLM queries) are brief and do not require a permanent dedicated core.
- Storage: A few MB for the code. If you use SQLite, count 10-50 MB. If you switch to PostgreSQL, plan for 1-2 GB of SSD storage for data.
Technical Recommendation
For a robust first deployment, aim for a VPS with:
- 1 vCPU (sufficient, bots are not continuously CPU-bound)
- 1 GB of RAM (the absolute minimum to avoid OOM - Out Of Memory crashes)
- 20 GB of SSD NVMe (more than enough)
This will cost between €3 and €5 per month with most modern cloud providers (Hetzner, DigitalOcean, OVH, Scaleway). It’s cheaper than a Spotify subscription, and you own the infrastructure.
Stack Choice: Node.js vs Python
In 2026, both languages dominate the Discord ecosystem. The choice doesn’t change feasibility, but it impacts maintainability and performance.
Node.js (Discord.js v14/v15)
Discord.js is the most popular library. It is asynchronous by default, making it very efficient for managing many simultaneous connections.
- Pros: Immense ecosystem, excellent documentation, high I/O performance (non-blocking). Ideal if you already have web/frontend skills.
- Cons: Memory management can become complex if you have reference leaks (memory leaks). “Callback hell” is avoided with
async/await, but the learning curve is steeper for beginners coming from typed languages. - Verdict: The default choice for 80% of bots in 2026.
Python (discord.py)
Discord.py remains a reference, especially for AI or data science-oriented bots.
- Pros: Simple syntax, easy to read. Excellent integration with AI libraries (LangChain, PyTorch) if your bot uses local models or LLM APIs.
- Cons: Slower in raw execution than Node.js for pure I/O operations. Managing asynchronous events (
asyncio) can be tricky if you mix synchronous and asynchronous code. - Verdict: Choose Python if your bot is heavily dependent on AI, data analysis, or if you come from the Python world.
Technical Deployment: From Installation to Production
We will assume you have access to a VPS running Ubuntu 24.04 LTS (the industry standard). We will use Node.js as the primary example, but the concepts apply to Python.
Step 1: Initial Server Security
Never log in as root. Create a dedicated user.
# On your local machine, generate an SSH key
ssh-keygen -t ed25519
# Copy the key to the VPS (replace user@ip)
ssh-copy-id user@vps_ip_address
# Connect
ssh user@vps_ip_address
Install base packages:
sudo apt update && sudo apt upgrade -y
sudo apt install git curl wget ufw -y
Enable the firewall (UFW) to allow only SSH and nothing else (your bot doesn’t need an open inbound port; it makes outbound requests).
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
Step 2: Installing the Runtime Environment
For Node.js:
# Use NodeSource to install the recommended LTS version (v20 or v22)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
Check versions:
node -v # Should display v22.x.x
npm -v # Should display 10.x.x
Note: For Python, install python3 and pip3, then use venv to isolate dependencies.
Step 3: Deploying the Code
Create a directory for your bot. We will use systemd as the primary process manager, as it is native, stable, and requires no third-party installation.
mkdir ~/my-discord-bot
cd ~/my-discord-bot
git clone https://github.com/your-account/your-bot.git .
npm install # Or pip install -r requirements.txt
Important: Never hardcode your TOKEN in the code. Use a .env file.
Create a .env file:
DISCORD_TOKEN=your_secret_token_here
DATABASE_URL=sqlite://./bot.db
Add .env to your .gitignore immediately.
Step 4: Process Management with systemd
This is the critical step for “24/7” operation. If the bot crashes, or if the VPS reboots (security updates, maintenance), systemd must restart the bot automatically.
Create a service file:
sudo nano /etc/systemd/system/discord-bot.service
Paste the following configuration (adapted for Node.js):
[Unit]
Description=Discord Bot Service
After=network.target
[Service]
Type=simple
User=your_linux_user # Replace with your Linux user
WorkingDirectory=/home/your_linux_user/my-discord-bot
ExecStart=/usr/bin/node index.js
Restart=on-failure
RestartSec=10
EnvironmentFile=/home/your_linux_user/my-discord-bot/.env
[Install]
WantedBy=multi-user.target
Explanation of keys:
Restart=on-failure: Restarts the bot only if it crashed (exit code != 0).RestartSec=10: Waits 10 seconds before restarting to avoid infinite loops if the problem persists (e.g., invalid token).EnvironmentFile: Loads environment variables without exposing them to other processes.
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable discord-bot.service # Start on boot
sudo systemctl start discord-bot.service
Check the status:
sudo systemctl status discord-bot.service
If everything is green, your bot is running. If it fails, check the logs:
journalctl -u discord-bot.service -f
Alternative: Docker vs Systemd
Docker is often recommended for isolation, but is it necessary for a Discord bot?
Quick Comparison
| Criterion | Systemd | Docker |
|---|---|---|
| Complexity | Low (native Linux) | Medium (Dockerfile, compose) |
| RAM Overhead | Almost none (~5-10 MB) | High (~50-100 MB for the daemon) |
| Isolation | None (shares kernel) | Strong (namespaces, cgroups) |
| Portability | OS-dependent (Ubuntu/Debian) | Portable everywhere |
| Maintenance | Standard OS updates | Docker image updates |
When to choose Docker?
- You are deploying multiple bots or services (e.g., bot + API + database) and want to orchestrate them.
- Your VPS has lots of RAM (> 2 GB) and you want to isolate dependencies.
- You want to be able to migrate the bot from one VPS to another by just copying the
docker-compose.ymland.env.
When to choose Systemd?
- You have a small VPS (1 GB RAM) and every MB counts.
- You want a simple, direct configuration.
- You don’t need strong isolation (a Discord bot doesn’t run as root; it runs under your user).
Our DevToolStack advice: For a single bot, stick with systemd. It’s lighter, easier to debug, and uses fewer system resources. Docker is a powerful tool, but here it’s like using a sledgehammer to crack a nut.
Token Security and Best Practices
The Discord token is the key to your bot. If someone retrieves it, they can control your bot, send messages on behalf of your server, or exfiltrate data.
- Never commit the token: Always check your
.gitignore. - Minimal permissions: When creating the bot in the Discord Developer Portal, enable only the necessary intents (e.g.,
Message Contentif you read messages,Server Membersif you manage roles). Fewer permissions = fewer risks. - Token rotation: If you suspect a token has leaked, generate a new one immediately in the developer portal. The old one will be invalidated.
- Log encryption: Ensure your code never logs the token. Not even in error logs. Use tools like
winstonorpinothat allow filtering sensitive fields.
Cost and Maintenance: The Real Price of 24/7
Hosting a bot in 2026 is extremely affordable.
Monthly Estimate
- Basic VPS (1 vCPU, 1 GB RAM): ~€3.50 / month (at Hetzner or OVH).
- Domain name (optional, for API): ~€10 / year.
- External database (if needed): ~€5 / month (if not using local SQLite).
Total: Approximately €4 to €5 per month.
Maintenance
A well-configured VPS with systemd requires very little attention.
- Security updates:
sudo apt update && sudo apt upgrade -yonce a month. - Monitoring: Install
htopto monitor RAM and CPU. If the bot consumes more than 500 MB of RAM, there is a memory leak to fix in the code. - Backups: Regularly back up the
.envfile and the database (if SQLite, copy the.dbfile). You can script this task withcron.
# Example cron for daily backup at 3 AM
crontab -e
# Add this line:
0 3 * * * cp /home/your_user/my-discord-bot/bot.db /home/your_user/backups/bot_$(date +\%Y\%m\%d).db
Which Choice for Your Profile?
To help you decide, here are typical scenarios:
Profile 1: The Absolute Beginner
- Stack: Node.js (Discord.js)
- Hosting: Ubuntu VPS with
systemd - Why: It’s the most direct path. You learn basic Linux, Git, and Node.js. No Docker overhead.
- Cost: €3.50/month.
Profile 2: The Python / AI Developer
- Stack: Python (Discord.py)
- Hosting: Ubuntu VPS with
systemd - Why: You are comfortable with Python. You can use
venvto isolate packages.systemdmanages the Python process just as well as Node. - Cost: €3.50/month.
Profile 3: The Architect / DevOps
- Stack: Node.js or Python
- Hosting: Docker with
docker-compose - Why: You want to deploy the bot, a PostgreSQL database, and a Redis cache in the same configuration file. You want the deployment to be reproducible on any machine.
- Cost: €5 to €10/month (to support Docker overhead and potentially more RAM).
Profile 4: The Hobbyist with Zero Budget
- Hosting: GitHub Actions (for scheduled tasks) + A small shared VPS or an old PC.
- Why: You can’t pay. Use a Raspberry Pi at home or a limited free VPS (but beware of outages).
- Cost: €0 (but high maintenance time and low reliability).
FAQ
1. My bot consumes a lot of RAM, what should I do?
First, check if it’s a memory leak. In Node.js, use --inspect to debug. If the bot loads the entire message history into memory, that’s bad practice. Use limited SQL queries or cache only the necessary data. Switch to SQLite if you are using an in-memory database.
2. Can I host multiple bots on the same VPS?
Yes, absolutely. Create a Linux user per bot, or use distinct subdirectories. Each bot will have its own systemd service (bot1.service, bot2.service). Just ensure that the sum of their RAM consumption does not exceed the VPS’s capacity.
3. How do I update my bot without downtime?
With systemd, you can update the code (git pull), then restart the service:
cd ~/my-discord-bot
git pull
sudo systemctl restart discord-bot.service
The outage will last a few seconds. If you want zero downtime, you need to set up a more complex deployment process (blue/green), but for a Discord bot, a 5-second outage is acceptable.
4. My bot is slow or dropping events. Why?
Check your VPS latency. A VPS that is too small or overloaded will struggle to maintain the WebSocket connection. Also, check that you don’t have synchronous blocking in your code. In Node.js, a blocking CPU-intensive operation can prevent the processing of other events. Use worker_threads or offload heavy tasks.
Hosting a Discord bot 24/7 is not a technical feat; it’s a matter of rigor. By choosing an economical VPS, using systemd for robustness, and properly securing your access, you get a professional infrastructure for the price of a coffee per month. Start simple, monitor your logs, and iterate. Your community will thank you for its constant availability.