← Back to Blog

How to Host a Discord Bot on a VPS (24/7, Ubuntu 24.04)

Published May 3, 2026  ·  10 min read  ·  Dakota Hopson, Galaxy Cloud Solutions

← Back to Blog

How to Host a Discord Bot on a VPS (24/7, Ubuntu 24.04)

Published May 3, 2026  ·  10 min read  ·  Dakota Hopson, Galaxy Cloud Solutions

Running a Discord bot on your local machine means it goes offline whenever your computer does. The proper solution is a VPS — a small server that stays online 24/7 and costs a few dollars a month. This guide covers hosting a Discord bot on Ubuntu 24.04 with proper process management so it automatically restarts if it crashes.

I'll cover three common bot setups: Node.js (discord.js), Python (discord.py), and a generic approach that works for anything.

⚡ The Nebula 1 plan ($5/mo) is perfect for a Discord bot — use code LAUNCH2026 for 50% off

What You Need

Step 1 — Connect to Your VPS

ssh [email protected]

Step 2 — Update the Server

apt update && apt upgrade -y

Step 3 — Install Your Runtime

For Node.js bots (discord.js):

curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
node --version

For Python bots (discord.py):

apt install -y python3 python3-pip python3-venv
python3 --version

Step 4 — Upload Your Bot Code

The easiest way is to clone from GitHub if your code is there:

git clone https://github.com/yourusername/your-bot.git /home/ubuntu/bot
cd /home/ubuntu/bot

Or copy files from your local machine with scp:

scp -r /path/to/your/bot [email protected]:/home/ubuntu/bot

Step 5 — Install Dependencies

Node.js:

cd /home/ubuntu/bot
npm install

Python:

cd /home/ubuntu/bot
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Step 6 — Store Your Bot Token Securely

Never hardcode your bot token in your code. Use an environment file:

cat > /home/ubuntu/bot/.env << 'EOF'
DISCORD_TOKEN=your_bot_token_here
EOF
chmod 600 /home/ubuntu/bot/.env

In your bot code, read it with dotenv (Node.js) or python-dotenv (Python) instead of hardcoding it.

Step 7 — Test It Runs

Node.js:

node index.js

Python:

source venv/bin/activate
python3 bot.py

Make sure it connects and your bot shows as online in Discord. Then stop it with Ctrl+C.

Step 8 — Create a Systemd Service

This keeps the bot running after you disconnect from SSH and restarts it automatically if it crashes.

For Node.js:

cat > /etc/systemd/system/discordbot.service << 'EOF'
[Unit]
Description=Discord Bot
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/bot
EnvironmentFile=/home/ubuntu/bot/.env
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

For Python:

cat > /etc/systemd/system/discordbot.service << 'EOF'
[Unit]
Description=Discord Bot
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/bot
EnvironmentFile=/home/ubuntu/bot/.env
ExecStart=/home/ubuntu/bot/venv/bin/python3 bot.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

Step 9 — Start and Enable the Service

systemctl daemon-reload
systemctl enable discordbot
systemctl start discordbot
systemctl status discordbot

Your bot is now running as a system service. It will start automatically when the VPS boots and restart automatically if it crashes.

Step 10 — Useful Commands

# Check if it's running
systemctl status discordbot

# View live logs
journalctl -u discordbot -f

# Restart after code changes
systemctl restart discordbot

# Stop the bot
systemctl stop discordbot

Updating Your Bot

When you push new code, update the VPS like this:

If using Git:

cd /home/ubuntu/bot
git pull
npm install  # or pip install -r requirements.txt
systemctl restart discordbot
Pro tip: Set up a GitHub Actions workflow to automatically SSH into your VPS and run the update commands whenever you push to main. That's a proper CI/CD pipeline for your bot.

How Much Does This Cost?

The Nebula 1 plan at Galaxy Cloud Solutions is $5/month. That's 1 vCPU, 1GB RAM, 20GB SSD. A Discord bot uses maybe 50-100MB of RAM. You could run several bots on the same VPS and still have plenty of room. Compare that to dedicated bot hosting services that charge $5-10/month per bot.

Host your Discord bot for $5/mo

The Nebula 1 plan is more than enough for most bots. Full root SSH access, Ubuntu 24.04, instant deployment. Use code LAUNCH2026 for 50% off your first month.

Get Started