🛠️ Tutorials · 11 min read

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.

S By Selfhostr Team · independent tests
ⓘ This article may contain affiliate links (no extra cost to you, it supports our tests). See the disclosure.

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:

Technical Recommendation

For a robust first deployment, aim for a VPS with:

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.

Python (discord.py)

Discord.py remains a reference, especially for AI or data science-oriented bots.

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:

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

CriterionSystemdDocker
ComplexityLow (native Linux)Medium (Dockerfile, compose)
RAM OverheadAlmost none (~5-10 MB)High (~50-100 MB for the daemon)
IsolationNone (shares kernel)Strong (namespaces, cgroups)
PortabilityOS-dependent (Ubuntu/Debian)Portable everywhere
MaintenanceStandard OS updatesDocker image updates

When to choose Docker?

  1. You are deploying multiple bots or services (e.g., bot + API + database) and want to orchestrate them.
  2. Your VPS has lots of RAM (> 2 GB) and you want to isolate dependencies.
  3. You want to be able to migrate the bot from one VPS to another by just copying the docker-compose.yml and .env.

When to choose Systemd?

  1. You have a small VPS (1 GB RAM) and every MB counts.
  2. You want a simple, direct configuration.
  3. 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.

  1. Never commit the token: Always check your .gitignore.
  2. Minimal permissions: When creating the bot in the Discord Developer Portal, enable only the necessary intents (e.g., Message Content if you read messages, Server Members if you manage roles). Fewer permissions = fewer risks.
  3. Token rotation: If you suspect a token has leaked, generate a new one immediately in the developer portal. The old one will be invalidated.
  4. Log encryption: Ensure your code never logs the token. Not even in error logs. Use tools like winston or pino that allow filtering sensitive fields.

Cost and Maintenance: The Real Price of 24/7

Hosting a bot in 2026 is extremely affordable.

Monthly Estimate

Total: Approximately €4 to €5 per month.

Maintenance

A well-configured VPS with systemd requires very little attention.

# 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

Profile 2: The Python / AI Developer

Profile 3: The Architect / DevOps

Profile 4: The Hobbyist with Zero Budget

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.

Tags: DiscordVPSNodePythonsystemdDocker

Related

🛠️ Tutorials

Hosting Nextcloud on a VPS in 2026: Complete Guide (Docker, HTTPS, Performance, Backups)

Comprehensive 2026 technical guide for deploying Nextcloud on a VPS using Docker. Covers server sizing, PostgreSQL and Redis optimization, HTTPS configuration, and reliable backup strategies.

Read
🛠️ Tutorials

Self-Hosting Your Website in 2026: Complete Guide (VPS, Docker, HTTPS)

2026 technical guide to self-hosting on a VPS: choosing plans, Docker setup, Let's Encrypt HTTPS, security, and real costs. Compare self-hosting vs. cloud.

Read
🛠️ Tutorials

Hosting n8n on a VPS in 2026: Complete Self-Hosted Guide (Docker, HTTPS, Backups)

2026 technical guide to self-hosting n8n on a VPS using Docker Compose, HTTPS, and security best practices. Compare cloud vs on-premise costs to automate workflows without subscriptions.

Read