Launch offer: -50% for your first 3 months with code LANCEMENT — new customers, VPS, first 50 orders, until 31 Dec 2026. See the VPS plans →
FranceHosta RootLab service
Please note: ordering, the customer area and our terms are currently available in French only.
Practical guide

Discord bot hosting on a VPS, 24/7

Does your bot run on your computer and stop as soon as you switch it off? A small VPS keeps it online all the time. This guide starts from a brand-new Debian or Ubuntu VPS and ends with a bot that restarts by itself.

Which VPS for a Discord bot?

A typical Discord bot (moderation, commands, reminders, a small game) uses very little: a few tens of megabytes of memory and almost no CPU. The VPS Mini (1 vCore, 1 GB of RAM, 10 GB SSD) is more than enough for one or several bots of this kind. Consider the VPS Start or larger if your bot uses a database, serves thousands of Discord servers, or shares the machine with a website.

Either KVM or LXC will do for a bot. If you are unsure, our KVM or LXC comparison will help you choose.

The first thing to sort out: Discord has no IPv6

Our VPS plans are IPv6 only, and Discord's servers (discord.com, the gateway.discord.gg gateway) are only reachable over IPv4. Without some setup, your bot will not be able to connect. The fix takes two minutes: configure a NAT64/DNS64 service, which relays connections to sites without IPv6 over IPv4. The steps are detailed in our guide on using GitHub over IPv6: it is exactly the same for Discord.

Once that is done, check:

getent ahostsv6 discord.com

If an IPv6 address is shown, your bot will be able to reach Discord.

Voice bots: music and voice go through Discord's voice servers over UDP, on IPv4. Public NAT64 relays do not always handle them well. For a music bot, test before committing for a long period; for a text bot, no problem.

1. Create the bot on the Discord side

  1. Open the Discord Developer Portal and create an application ("New Application").
  2. In the Bot tab, generate the bot's token and copy it. It is your bot's password: never publish it, neither on GitHub nor in a message.
  3. Still in the Bot tab, enable Message Content Intent if your bot needs to read message content (as in the example below).
  4. Under OAuth2, generate an invite link with the bot scope and the permissions you need, then invite the bot to your server.

2. Prepare the VPS

Connect over SSH (see the IPv6 VPS guide), update the system and install Node.js:

apt update && apt upgrade -y
apt install -y nodejs npm
node --version

discord.js requires a recent version of Node.js: if node --version shows less than the version given in the discord.js documentation, install a newer one from nodejs.org (reachable over IPv6).

Do not run the bot as root. Create a dedicated user for it:

adduser --system --group --home /srv/bot bot

3. Install the bot

cd /srv/bot
sudo -u bot npm init -y
sudo -u bot npm install discord.js

Create the file /srv/bot/index.js with a minimal bot that replies "pong" to "!ping":

const { Client, Events, GatewayIntentBits } = require('discord.js');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
    ],
});

client.once(Events.ClientReady, c => console.log(`Logged in as ${c.user.tag}`));

client.on(Events.MessageCreate, message => {
    if (message.content === '!ping') message.reply('pong');
});

client.login(process.env.DISCORD_TOKEN);

The token is read from an environment variable and never written in the code. Store it in a file that only the bot's user can read:

echo 'DISCORD_TOKEN=paste-your-token-here' > /srv/bot/.env
chown bot:bot /srv/bot/.env
chmod 600 /srv/bot/.env

(Replace paste-your-token-here with your real token.) If you already have a Python bot (discord.py), the approach is the same: install python3-venv, create a virtual environment in /srv/bot and adapt the ExecStart line below.

4. Keep it online with systemd

systemd starts the bot with the server and restarts it if it crashes. Create /etc/systemd/system/bot-discord.service:

[Unit]
Description=Discord bot
After=network-online.target
Wants=network-online.target

[Service]
User=bot
WorkingDirectory=/srv/bot
EnvironmentFile=/srv/bot/.env
ExecStart=/usr/bin/node index.js
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Then enable it:

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

The last command shows the bot's messages live: you should see the "Logged in as…" line from the example code. Type !ping on your Discord server: the bot replies from your VPS. To update the code later, edit the files and run systemctl restart bot-discord.

Frequently asked questions

Which VPS should I choose for a Discord bot?

The VPS Mini (1 vCore, 1 GB of RAM) is enough for one or several text bots. Take the VPS Start or larger if the bot uses a database, serves a very large number of servers or shares the machine with other services.

Can my bot connect to Discord over IPv6?

Not directly: Discord's servers are only reachable over IPv4. A NAT64/DNS64 service solves the problem in a few minutes, as explained in our NAT64 guide.

Does a music bot work?

Voice goes through Discord's voice servers over UDP on IPv4, which public NAT64 relays do not always handle well. Test before committing; a text bot, on the other hand, works without any trouble.

Can I host several bots on the same VPS?

Yes. Create one systemd service per bot, each with its own folder and token file.

A VPS for your bot, from €1.49

Root access, SSD, ECC RAM, hosted in France by a nonprofit. Ready in a few minutes.