Host a Discord bot on your Linux VPS
- Updated 17 November 2026
- 3 min read
A Linux VPS is ideal for hosting a Discord bot: it stays online around the clock, even when your computer is off. This guide shows you how to install your bot, run it and have it restart on its own, with Node.js (discord.js) or Python (discord.py).
Good to knowA Discord bot connects out to Discord's servers by itself. It needs no open port in your VPS firewall.
Before you start
- your bot's code, on your computer or in a Git repository (GitHub, GitLab…);
- the bot token, copied from the Discord Developer Portal, Bot tab;
- SSH access to your VPS: follow the guide Connect to your Linux VPS over SSH.
WarningThe token gives full control of your bot. Never publish it on GitHub or in a message: if it leaks, regenerate it right away in the Discord portal.
1. Prepare the server
Logged in as root, update the system and create a dedicated user for the bot. It won't run as administrator, which limits the risks.
apt update && apt upgrade -y
apt install -y git
adduser --disabled-password --gecos "" discordbotOn Rocky Linux or AlmaLinux, replace the first two lines with dnf upgrade -y && dnf install -y git and create the user with useradd -m discordbot.
2. Install Node.js or Python
JavaScript bot (discord.js)
Install the LTS version of Node.js from the official NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt install -y nodejs
node -vOn Rocky Linux or AlmaLinux: curl -fsSL https://rpm.nodesource.com/setup_24.x | bash - then dnf install -y nodejs.
Python bot (discord.py)
Python 3 is already installed on Debian and Ubuntu. Just add the virtual environment tool:
apt install -y python3-venv python3-pip3. Upload the bot's code
Switch to the bot user, then fetch your code. From a Git repository:
su - discordbot
git clone https://github.com/your-account/your-bot.git bot
cd botTipWithout a Git repository, upload the folder from your computer with scp -r my-bot root@203.0.113.10:/home/discordbot/bot, then hand it over to the bot user with chown -R discordbot: /home/discordbot/bot.
Store the token in a .env file that only you can read:
echo "DISCORD_TOKEN=paste_your_token_here" > .env
chmod 600 .envFinally, install the dependencies. For Node.js:
npm ci || npm installFor Python:
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt4. Test the bot
Run it once by hand, with node index.js or .venv/bin/python bot.py depending on your project. The bot should show as online on Discord. Stop it with Ctrl + C, then go back to root with exit.
5. Keep the bot running
To keep the bot running, restart it after a crash and bring it back with the VPS, create a systemd service:
nano /etc/systemd/system/discordbot.servicePaste this content. For a Python bot, replace the ExecStart line with ExecStart=/home/discordbot/bot/.venv/bin/python bot.py.
[Unit]
Description=Discord bot
After=network-online.target
Wants=network-online.target
[Service]
# The bot runs as its own user, without admin rights
User=discordbot
WorkingDirectory=/home/discordbot/bot
# The token is read from the .env file
EnvironmentFile=/home/discordbot/bot/.env
ExecStart=/usr/bin/node index.js
# If it crashes, restart automatically after 5 seconds
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetEnable and start the service:
systemctl daemon-reload && systemctl enable --now discordbot
systemctl status discordbotThe status should read active (running). Your bot is now online for good.
Managing the bot day to day
- watch the bot's output live:
journalctl -u discordbot -f; - restart the bot:
systemctl restart discordbot; - stop it:
systemctl stop discordbot.
To update the bot from Git:
su - discordbot -c "cd bot && git pull && npm install" && systemctl restart discordbotTipOne VPS can host several bots. Create one service per bot (bot1.service, bot2.service…), each with its own folder and its own .env file.
