Self-hosting a Discord bot (and when bot hosting is easier)
Updated: 12 August 2026 · Guide · VPS · Discord bot
At its core, a Discord bot is a program that runs around the clock and logs in to the Discord API with a token. On a VPS that means: install the runtime, upload the code, keep the process alive permanently.
Runtime
Depending on the bot's programming language, you need Node.js or Python:
sudo apt install nodejs npm # or, for Python bots: sudo apt install python3 python3-pip
Upload and start the bot
Get the code onto the server via SFTP or Git, install the dependencies, and set the token as an environment variable instead of leaving it somewhere in the code:
npm install DISCORD_TOKEN=<token> node index.js
Like this, the bot only runs as long as the SSH session stays open. For permanent operation it belongs in pm2 (for Node.js) or a systemd service, including an automatic restart after a crash:
sudo npm install -g pm2 pm2 start index.js --name my-bot pm2 startup pm2 save
Where it gets uncomfortable
Node updates by hand, a token in a file you have to secure yourself, a crash at three in the morning that nobody notices at first.
That's exactly what ready-made bot hosting is for: upload the bot, it runs, automatic restart on crash, no server of your own to maintain. Details: /discord-bots.
Storing the token properly
The bot token is your bot's password: whoever has it controls it completely. Two mistakes happen particularly often: the token sits directly in the source code and ends up in a public repository with the first push, or it lies in a file that every user on the server can read. Both are easy to avoid:
printf 'DISCORD_TOKEN=<token>\n' > ~/my-bot/.env chmod 600 ~/my-bot/.env echo '.env' >> ~/my-bot/.gitignore
If a token has become public after all, deleting the commit won't help. It has to be regenerated in Discord's developer portal. Otherwise the old one stays valid.
A systemd service for Python bots
pm2 is handy for Node.js; for Python bots systemd is the more direct route. The unit goes in /etc/systemd/system/my-bot.service:
[Unit] Description=Discord Bot After=network-online.target [Service] User=<username> WorkingDirectory=/home/<username>/my-bot EnvironmentFile=/home/<username>/my-bot/.env ExecStart=/usr/bin/python3 bot.py Restart=always RestartSec=15 [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable --now my-bot sudo journalctl -u my-bot -n 50 -f
Restart=always instead of on-failure is deliberate here: a bot that exits normally after an API error should still come back. RestartSec prevents it from restarting in a loop every second if there is a persistent problem.
How much RAM does a bot need?
Less than most people assume. A bot that responds to commands and occasionally queries an API usually gets by with a few hundred megabytes. It only needs considerably more once it streams music, holds larger amounts of data in memory or runs on a great many servers at once.
You can see what you actually use while it runs; you don't have to guess:
systemctl status my-bot | grep Memory ps -o pid,rss,cmd -C python3
Your own VPS or bot hosting?
Your own VPS is worth it when the bot is part of something bigger: a database alongside it, a website with it, several services on the same machine. Then the server carries several jobs, and the setup work is spread out.
If only the bot runs, on the other hand, with a VPS you pay for an entire operating system that you have to maintain yourself, just to keep a single program alive. With bot hosting you upload the code, the runtime is in place, the restart after a crash is built in, and operating system updates are not your concern. For a single bot that is, as a rule, the cheaper and calmer route.
- See Discord bot hostingNode.js runtime, console and backups in the panel
- Prefer your own VPSIf the bot is just one service among several
- First: secure your VPSSet up SSH key and firewall