AtmosNode

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

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.

Bash
apt update && apt upgrade -y
apt install -y git
adduser --disabled-password --gecos "" discordbot

On 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:

Bash
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt install -y nodejs
node -v

On 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:

Bash
apt install -y python3-venv python3-pip

3. Upload the bot's code

Switch to the bot user, then fetch your code. From a Git repository:

Bash
su - discordbot
git clone https://github.com/your-account/your-bot.git bot
cd bot

TipWithout 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:

Bash
echo "DISCORD_TOKEN=paste_your_token_here" > .env
chmod 600 .env

Finally, install the dependencies. For Node.js:

Bash
npm ci || npm install

For Python:

Bash
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt

4. 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:

Bash
nano /etc/systemd/system/discordbot.service

Paste this content. For a Python bot, replace the ExecStart line with ExecStart=/home/discordbot/bot/.venv/bin/python bot.py.

INI
[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.target

Enable and start the service:

Bash
systemctl daemon-reload && systemctl enable --now discordbot
systemctl status discordbot

The 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:

Bash
su - discordbot -c "cd bot && git pull && npm install" && systemctl restart discordbot

TipOne VPS can host several bots. Create one service per bot (bot1.service, bot2.service…), each with its own folder and its own .env file.

No server yet?

AMD Ryzen, NVMe and dedicated DDR5 RAM, from €31.99 per month.

See Linux VPS plans

Need help?

A question? Our team answers you through a ticket.

Open a ticket

In the same category