How to Host a Discord Bot on a VPS 24/7
Key takeaways
- A VPS keeps your Discord bot online 24/7 because it never sleeps, closes its lid, or drops off home Wi-Fi like a laptop does.
- Python (57.9%) and Node.js (48.7%) are the two most-used tools among developers in the 2025 Stack Overflow survey, and both run cleanly on a small Linux VPS.
- Use pm2 for quick Node.js restarts or systemd for language-agnostic, boot-persistent supervision, so your bot recovers automatically after a crash or reboot.
- Never commit your bot token to Git. Store it in an environment file with locked-down permissions and rotate it immediately if it leaks.
Learn to host a Discord bot on a VPS with Node.js or Python, keep it online 24/7 using pm2 or systemd, and secure your tokens.
To host a Discord bot on a VPS 24/7, you rent a small Linux server, install a Node.js or Python runtime, and wrap your bot in a process manager like pm2 or systemd so it restarts on its own. That setup keeps the bot online while your laptop is closed, your home internet drops, or your machine reboots for updates. The rest is securing your token and keeping the code current.
This guide walks through each step in order, with copy-pasteable commands you can run over SSH. It assumes you already have a working bot and a Discord application token. If you are still building the bot, finish that first, then come back to deploy it.
Why a VPS Beats a Laptop for an Always-On Bot
A laptop is the wrong tool for a 24/7 service because it sleeps, updates, and shares an unstable home connection. A VPS is a dedicated slice of a server that stays powered on in a datacenter with redundant networking, so your bot answers commands at 3 a.m. without you thinking about it.
The runtime choice is friendly here. In the 2025 Stack Overflow Developer Survey, Python was the single most-used language at 57.9%, and Node.js was used by 48.7% of respondents (Stack Overflow Developer Survey 2025). Both are first-class citizens on any Linux VPS, so you are not fighting your host to run popular tooling.
A laptop also ties uptime to your physical presence. Close the lid and the bot goes dark. A VPS removes that link entirely. If you are weighing the trade-offs before committing, our guide on when a VPS makes sense over shared hosting breaks down where each option fits.
For a bot, you rarely need much hardware. A single small-to-medium bot runs fine in 512MB to 1GB of RAM, which is why an entry KVM plan is usually plenty to start.

Setting Up a Node.js or Python Runtime
Getting a runtime ready takes about five minutes on a fresh Linux VPS. The pattern is the same for both languages: create a non-root user, install the interpreter, pull your code, then install dependencies. Running the bot under a dedicated user, not root, limits the damage if the process is ever compromised.
Start by SSHing in and creating a service account:
adduser bot
usermod -aG sudo bot
su - bot
For a Node.js bot, install the current LTS release and confirm it:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v && npm -v
For a Python bot, use the system Python 3 and an isolated virtual environment so your dependencies never clash with the OS:
sudo apt-get install -y python3 python3-venv python3-pip
python3 -m venv ~/botenv
source ~/botenv/bin/activate
Now pull your project and install its dependencies. Use npm install for Node.js or pip install -r requirements.txt for Python. A quick manual run confirms the bot connects before you hand it to a supervisor:
node index.js # Node.js
python3 bot.py # Python
If it logs in and responds to a command, stop it with Ctrl+C. You are ready to make it permanent. If your VPS itself is brand new, our step-by-step VPS setup guide covers the base configuration first.
Keeping the Bot Alive With pm2 or systemd
A manual node index.js dies the moment you close SSH. To keep a Discord bot on a VPS running 24/7, you need a supervisor that restarts it after crashes and after reboots. The two standard tools are pm2 for Node.js and systemd for anything.
pm2 is the fast path for JavaScript bots. It is a widely adopted Node.js process manager with logging, restarts, and boot persistence built in:
sudo npm install -g pm2
pm2 start index.js --name discord-bot
pm2 save
pm2 startup # follow the printed command to enable on boot
Check status any time with pm2 status and read logs with pm2 logs discord-bot. If the bot throws an uncaught error, pm2 relaunches it within seconds.
systemd is the language-agnostic option and ships with every modern Linux distribution. It works equally well for Python. Create /etc/systemd/system/discord-bot.service:
[Unit]
Description=Discord Bot
After=network.target
[Service]
User=bot
WorkingDirectory=/home/bot/mybot
ExecStart=/home/bot/botenv/bin/python3 bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Then enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now discord-bot
sudo systemctl status discord-bot
The Restart=always line is what buys you 24/7 uptime. If the process exits for any reason, systemd waits five seconds and brings it back, including after a full server reboot.

Securing Tokens and Managing Updates
Your bot token is a password. Anyone who has it can impersonate your bot, so treat it with the same care you would an SSH key. The most common leak is committing a token straight into a public Git repository.
Keep the token out of your code entirely. Store it in an environment file and lock down who can read it:
echo 'DISCORD_TOKEN=your-token-here' > ~/mybot/.env
chmod 600 ~/mybot/.env
echo '.env' >> ~/mybot/.gitignore
Load it at runtime with a library like dotenv (Node.js) or python-dotenv (Python) and read process.env.DISCORD_TOKEN or os.environ["DISCORD_TOKEN"]. If a token ever leaks, regenerate it immediately in the Discord Developer Portal. The official Discord developer documentation covers token handling and API pacing in detail.
For updates, keep a simple, repeatable routine. Pull new code, install any new dependencies, then restart the supervisor:
cd ~/mybot && git pull
npm install # or: pip install -r requirements.txt
pm2 restart discord-bot # or: sudo systemctl restart discord-bot
Harden the server itself while you are at it. Enable a firewall, disable password SSH in favor of keys, and keep the OS patched. Those basics matter far more than any single bot setting.
Scaling to Multiple Bots and Servers
One VPS can comfortably host several bots at once, since most bots idle at low CPU and small memory. Both pm2 and systemd handle this by giving each bot its own named process or service, so a crash in one never touches the others.
With pm2, an ecosystem file lets you define and launch everything together:
module.exports = {
apps: [
{ name: "mod-bot", script: "mod/index.js" },
{ name: "music-bot", script: "music/index.js" }
]
}
Run pm2 start ecosystem.config.js and both boot at once. With systemd, you simply create one .service file per bot. Either way, pm2 status or systemctl gives you a clean view of what is running.
You will feel pressure to grow when RAM fills up or a bot needs heavier work like audio streaming or image processing. At that point, add more memory, split noisy bots onto a second VPS, or move up a plan tier. Bytehosty's KVM VPS plans include unmetered traffic and NVMe storage, which keeps a chatty multi-bot setup responsive without surprise bandwidth bills.
The goal is boring reliability: a server that stays up, restarts your bots on its own, and lets you deploy an update in three commands. Pick a runtime, wrap it in a supervisor, lock down the token, and your bot answers every command around the clock.
Ready to deploy? Spin up a small KVM VPS with full root access and follow the steps above start to finish.
Questions covered
Can I host a Discord bot on a VPS for free?
Not reliably. Free tiers usually sleep after inactivity or cap runtime, which kills a 24/7 bot. A low-cost KVM VPS with unmetered traffic is the cheapest way to stay online around the clock.
How much RAM does a Discord bot need?
A single small-to-medium bot runs comfortably in 512MB to 1GB of RAM. Bots handling music streaming, image processing, or large member counts benefit from 2GB or more.
Should I use pm2 or systemd for my bot?
Use pm2 if you run Node.js and want simple logs and restarts. Use systemd if you want a language-agnostic service that starts on boot and integrates with the OS. Both keep the bot alive after a crash.
Do I need root access to host a Discord bot?
Yes, for the initial setup. Root lets you install runtimes, create a service user, and configure a firewall. After setup, run the bot itself under an unprivileged user for safety.
Will hosting a bot on a VPS get me rate-limited by Discord?
No. Rate limits come from how your code calls the API, not from where it runs. Follow the pacing rules in Discord's developer documentation and the bot behaves identically on a VPS or a laptop.