Back to Articles
VPS
8 min reading time

How to Host a Discord Bot on a VPS (Step by Step)

Orihost Icon
Orihost
Posted by
November 19, 2026
Date Published
How to Host a Discord Bot on a VPS (Step by Step)

Before You Start

A VPS gives your bot its own machine, with full root access and no limits on which libraries or background services you install. This guide uses a Debian or Ubuntu server and a Node.js bot, with notes for Python. You need:

  • A VPS with SSH access (any Orihost VPS plan works; Start is plenty for most bots)
  • Your bot's code in a Git repository
  • Your bot token, kept out of the repository

1. Log In and Update the Server

bash
ssh root@your-server-ip apt update && apt upgrade -y

2. Create a User for the Bot

Running a bot as root means a bug or a leaked token can damage the whole server. Give it its own user:

bash
adduser --disabled-password --gecos "" bot

3. Install the Runtime

For Node.js, install the current LTS release from the NodeSource repository or with your distribution's packages:

bash
apt install -y nodejs npm git node --version

For Python, install python3, python3-venv and git instead, and create a virtual environment in the bot's folder.

4. Get the Code and Add the Token

bash
su - bot git clone https://github.com/you/your-bot.git cd your-bot npm ci echo "DISCORD_TOKEN=your-token-here" > .env chmod 600 .env exit

Never commit the .env file. If a token ever leaks, reset it in the Discord Developer Portal right away.

5. Keep It Running With systemd

A systemd service starts the bot at boot and restarts it if it crashes. Create /etc/systemd/system/discord-bot.service:

ini
[Unit] Description=Discord bot After=network-online.target [Service] User=bot WorkingDirectory=/home/bot/your-bot EnvironmentFile=/home/bot/your-bot/.env ExecStart=/usr/bin/node index.js Restart=always RestartSec=5 [Install] WantedBy=multi-user.target

Then enable and start it:

bash
systemctl daemon-reload systemctl enable --now discord-bot journalctl -u discord-bot -f

6. Turn On a Firewall

A Discord bot only makes outgoing connections, so it needs no open ports. Allow SSH and deny the rest:

bash
apt install -y ufw ufw allow OpenSSH ufw enable

If you add a web dashboard later, open only its port (or put it behind a reverse proxy on 80 and 443).

7. Updating the Bot

bash
su - bot -c "cd your-bot && git pull && npm ci" systemctl restart discord-bot

Keep It Secure

Switch SSH to key-only login, install security updates automatically and keep backups off the server. Our Linux hardening checklist for a new VPS covers each step.

When Managed Bot Hosting Is Easier

A VPS is the right call when your bot shares a server with a dashboard, a database and other services, or when you want full control. If you just want the bot online without managing Linux, managed bot hosting gives you a panel, daily backups and a MySQL database from €1/month.

Get a Server

Every Orihost VPS is a KVM server with full root access, a dedicated IPv4, NVMe storage and RAM that is never oversold, from €7.99/month.

VPSDiscord BotsLinuxGuide

Need a professional setup?

Join the developers who run their bots, sites and servers on Orihost. Plans from €1/month, live in minutes.