If your Discord bot keeps going offline, it’s almost certainly because you’re hosting it somewhere that sleeps. Replit sleeps after 5 minutes of inactivity. Railway and Render cut free plans. Glitch throttles CPU. Heroku’s free tier is dead.
The right answer is a VPS — a real server that runs 24/7 because that’s literally what it’s for. This guide shows you exactly how to set one up for a Node.js or Python Discord bot, keep it online permanently, and auto-restart it if it ever crashes. The whole process takes about 20 minutes.
Why Your Discord Bot Needs a VPS (Not Replit or Railway)
Here’s the honest breakdown of where developers try to host bots and what actually happens:
| Platform | Free Plan Reality | Verdict |
|---|---|---|
| Replit | Sleeps after 5 min of inactivity, requires hacky ping workarounds that Replit actively blocks | ❌ Not reliable |
| Railway | Free tier removed in 2023, $5/month minimum now | ❌ No longer free |
| Render | Free web services sleep after 15 min. Background workers require paid plan | ❌ Sleeps |
| Glitch | Apps sleep after 5 min, banned ping services like UptimeRobot to prevent workarounds | ❌ Blocked workarounds |
| Heroku | Free dynos completely removed in November 2022 | ❌ Dead |
| Oracle Always Free | Powerful but known to randomly delete instances after 60 days with no warning | ⚠️ Risky for production |
| Free VPS (VPSWala) | Real server, public IP, runs 24/7, no sleeping, no surprise deletions | ✅ Reliable |
A VPS is what serious bot developers use. You get a real Linux server with root access, it’s always on, and you control everything — including what happens when your bot crashes (spoiler: PM2 restarts it automatically).
What You Need Before You Start
- A working Discord bot (Node.js with discord.js, or Python with discord.py)
- Your bot’s token from the Discord Developer Portal
- A free VPS with Ubuntu 22.04 — grab one here, no credit card needed
- An SSH client (Terminal on Mac/Linux, PuTTY or Windows Terminal on Windows)
If your bot isn’t written yet, the discord.js guide and the discord.py docs are the best starting points. Come back here when you have a working bot file.
Step 1 — Get a Free VPS and Connect via SSH
You need a VPS with a public IP address that stays on 24/7. VPSWala’s free VPS deploys in 60 seconds — pick Ubuntu 22.04, choose a location close to your Discord server’s region (US East, EU, or Asia), and you’ll get SSH credentials by email.
Connect to your VPS:
ssh root@YOUR_VPS_IP
On Windows, open Windows Terminal or PowerShell and run the same command. If you’re using PuTTY, enter your IP in the hostname field and connect on port 22.
You should see the Ubuntu welcome screen. You’re in.
Step 2 — Update the Server
Always do this first on a fresh VPS:
sudo apt update && sudo apt upgrade -y
This takes 1–2 minutes. It ensures you’re not running into security patches or dependency issues later.
Step 3A — Set Up Node.js (for discord.js bots)
Ubuntu’s default Node.js is usually outdated. Install the current LTS version using NodeSource:
# Install NodeSource repo for Node.js 20 LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
# Install Node.js
sudo apt install -y nodejs
# Verify versions
node --version
npm --version
You should see v20.x.x or higher. If you need Node 18 instead, replace setup_20.x with setup_18.x.
Skip to Step 4 if you’re using Node.js.
Step 3B — Set Up Python (for discord.py bots)
Ubuntu 22.04 ships with Python 3.10. Check it:
python3 --version
Install pip and venv:
sudo apt install -y python3-pip python3-venv
Create a virtual environment for your bot — this keeps dependencies clean and isolated:
mkdir ~/discordbot
cd ~/discordbot
python3 -m venv venv
source venv/bin/activate
Install discord.py inside the venv:
pip install discord.py
# If your bot uses voice features:
pip install "discord.py[voice]"
# Verify install
python3 -c "import discord; print(discord.__version__)"
Step 4 — Upload Your Bot Files
Get your bot code onto the VPS. You have three options:
Option A — Git (recommended if your code is on GitHub)
sudo apt install -y git
git clone https://github.com/YOUR_USERNAME/YOUR_BOT_REPO.git ~/discordbot
cd ~/discordbot
Option B — SCP from your local machine
# Run this on your LOCAL machine, not the VPS
scp -r /path/to/your/bot root@YOUR_VPS_IP:~/discordbot
Option C — nano/vim directly on the server
If your bot is simple (single file), just create it directly:
mkdir ~/discordbot
cd ~/discordbot
nano bot.js # or bot.py
Paste your code, save with Ctrl+O, exit with Ctrl+X.
Install dependencies
For Node.js:
cd ~/discordbot
npm install
For Python (with venv active):
cd ~/discordbot
source venv/bin/activate
pip install -r requirements.txt
Step 5 — Install PM2 Process Manager
PM2 is the most important part of this setup. It’s a process manager that:
- Keeps your bot running in the background (no need to keep the SSH session open)
- Automatically restarts the bot if it crashes
- Restarts everything if the server reboots
- Gives you logs, monitoring, and status in one command
sudo npm install -g pm2
Verify:
pm2 --version
PM2 works for both Node.js and Python bots — it just runs whatever command you give it and manages the process.
Step 6 — Run Your Bot with PM2
For Node.js bots:
cd ~/discordbot
pm2 start bot.js --name "discord-bot"
Replace bot.js with your actual entry file name (could be index.js, main.js, etc.).
For Python bots:
cd ~/discordbot
pm2 start venv/bin/python3 --name "discord-bot" -- bot.py
This tells PM2 to run the Python interpreter inside your venv, passing bot.py as the argument.
Check it’s running:
pm2 status
You should see your bot listed with status online in green. If it shows errored, check the logs immediately:
pm2 logs discord-bot
Common causes of errors at this stage: wrong file name, missing environment variable for bot token, or a dependency that didn’t install correctly.
Step 7 — Auto-Restart on Server Reboot
Right now, if the server restarts (updates, power cycle, etc.), your bot won’t come back online automatically. Fix this in one command:
pm2 startup
PM2 will print a command for you to copy and run — it looks something like:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u root --hp /root
Copy that exact command from your terminal output and run it. Then save your current process list:
pm2 save
That’s it. Your bot will now automatically start on every server reboot, and PM2 will restart it within seconds if it crashes for any reason.
Test the reboot behavior:
sudo reboot
Wait 30 seconds, SSH back in, and run pm2 status. Your bot should be running.
Step 8 — Secure Your Bot Token
Hardcoding your token directly in the bot file is the most common security mistake. If you ever push that file to GitHub, your token gets exposed and Discord will invalidate it within minutes.
The right way is an environment variable stored in a .env file:
cd ~/discordbot
nano .env
DISCORD_TOKEN=your_actual_token_here
Save and exit. Lock down the file permissions:
chmod 600 .env
Load it in Node.js:
npm install dotenv
At the top of your bot file:
require('dotenv').config();
const token = process.env.DISCORD_TOKEN;
Load it in Python:
pip install python-dotenv
from dotenv import load_dotenv
import os
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
Add .env to your .gitignore file so it never gets committed:
echo ".env" >> .gitignore
Step 9 — Monitor Your Bot
PM2 gives you everything you need to keep tabs on your bot:
# See all running processes and their status
pm2 status
# View live logs
pm2 logs discord-bot
# View last 100 lines of logs
pm2 logs discord-bot --lines 100
# Real-time monitoring dashboard
pm2 monit
# Restart manually
pm2 restart discord-bot
# Stop the bot
pm2 stop discord-bot
# Delete from PM2 list
pm2 delete discord-bot
The pm2 monit dashboard is particularly useful — it shows CPU usage, memory, uptime, and live logs in a terminal UI.
For a bot on the free VPS tier (1 vCPU, 2GB RAM), a typical Discord bot uses around 50–150MB RAM and under 2% CPU at idle. You can comfortably run 3–4 bots on a single free VPS instance before needing to upgrade.
Common Issues and Fixes
| Problem | Likely Cause | Fix |
|---|---|---|
| Bot shows “errored” in PM2 | Crash on startup | Run pm2 logs discord-bot — the error message will tell you exactly what’s wrong |
| Bot online but not responding | Wrong intents or missing permissions | Check Discord Developer Portal — enable Message Content Intent under Privileged Gateway Intents |
| Token invalid error | Token pasted incorrectly or regenerated | Go to Developer Portal, regenerate token, update your .env file |
| Module not found (Node.js) | npm install wasn’t run | cd into bot folder, run npm install |
| ModuleNotFoundError (Python) | Running outside venv or requirements not installed | Activate venv first: source venv/bin/activate, then pip install -r requirements.txt |
| Bot goes offline after SSH disconnect | Bot started directly, not via PM2 | Stop the direct process, start with pm2 start instead |
| Bot doesn’t restart after reboot | PM2 startup/save not run | Run pm2 startup, copy the generated command, run it, then pm2 save |
| High memory usage over time | Memory leak in bot code | Add --max-memory-restart 200M to PM2 start command to auto-restart if memory exceeds 200MB |
Free VPS vs Paid Bot Hosting — Which Is Right for You?
There are dedicated Discord bot hosts out there (PebbleHost, SparkedHost, etc.) that offer a simpler panel interface. Here’s how they compare to a free VPS:
| Free VPS (VPSWala) | Dedicated Bot Host | |
|---|---|---|
| Cost | Free forever | $3–10/month typically |
| Control | Full root access — run anything | Limited to their panel and supported languages |
| Multiple bots | Yes — run as many as RAM allows | Usually 1 per plan |
| Other services | Yes — web server, database, VPN, anything | Bot only |
| Setup complexity | 15–20 min (what this guide is for) | 5 min with one-click installer |
| Custom dependencies | Install anything via apt or pip | Limited to what the host supports |
| Best for | Developers who want full control and zero cost | Non-technical users who want simplest possible setup |
If you’re comfortable with a terminal, the free VPS wins on every dimension except setup time — and this guide covers that. You also get a full Linux server you can use for other things: web hosting, databases, a VPN, a Minecraft server, whatever you want, all on the same free instance.
Your bot is now running 24/7, auto-restarting on crash, and surviving server reboots. You can close the SSH session and it’ll keep going.
If you’re running a larger bot — a music bot, a bot serving multiple servers with heavy command load, or multiple bots on the same instance — the Professional free vps trial gives you 8-core AMD EPYC and 8GB DDR5 RAM, which handles that load comfortably with headroom to spare.
For the next steps, check out our guide on setting up a database for your bot or deploying a web dashboard alongside it.

