Skip to content

Hosting

How to host a Discord bot: VPS, Docker and panels compared

Ways to keep a Discord bot online all day: a VPS with pm2, Docker, a Pterodactyl panel, a Node.js host or a home computer, with the trade-offs of each.

· Updated · 7 min read
Cover image: How to host a Discord bot: VPS, Docker and panels compared

A Discord bot answers only while its program is running. The program has to be online as long as you want the bot to be. This guide compares the usual ways to keep it running, from a small server to a free tier, and what to watch for.

What the bot needs

  • Node.js 18 or newer.
  • The files of the project and its dependencies installed with npm install.
  • The environment variables in a place the host reads them: the token, the client id and optional ones.
  • A way to restart the program if it crashes or the machine reboots.

The bot makes an outgoing connection to Discord. It does not need an open port, a domain or a web server.

A VPS with pm2

A small virtual server is the most flexible option. You install Node.js, copy the project and run it under a process manager that restarts it. pm2 is a common one.

npm install -g pm2
pm2 start index.js --name my-bot
pm2 save
pm2 startup

A VPS gives you full control, logs and the ability to run several bots. You are responsible for updates and security.

Docker

A container packages the bot with its Node version, so it runs the same everywhere. A short Dockerfile based on a Node image, with npm install and npm start, is enough. Pass the environment variables to the container instead of baking them in.

A Pterodactyl panel

Many game server hosts and communities use Pterodactyl. A Node.js egg lets you upload the files, set the variables in the panel and start the bot with a button. This is the easiest route if you already host game servers.

Hosts for Node.js apps

Several services run Node.js programs and restart them for you. Check that the plan supports a worker that runs all the time and has no sleep mode. A bot that sleeps goes offline and misses events. Free plans change often, so read the current terms.

Your own computer or a Raspberry Pi

For a hobby bot, a computer at home is enough. The bot is offline when the machine sleeps or loses the connection. A Raspberry Pi that stays on is a cheap always-online option.

Keep the token safe

  • Put it in the host environment variables, not in the code.
  • Do not commit the .env file. The generated project has a .gitignore for it.
  • If it leaks, reset it in the Developer Portal at once.

Back up the data

Bots made with BotsMaker keep their data in the data folder as JSON files. Include it in your backups, and keep it when you update the code.

Written by

BotsMaker Team

We build BotsMaker, the AI Discord bot creator. The guides come from what we see when bots are generated, tested and set up in the Discord Developer Portal and on real hosts.

More guides

RSS feed · All guides