Why a bot needs a host
A Discord bot is a program that keeps a connection open to Discord. It logs in with a token, holds a WebSocket to Discord’s gateway and sends a regular heartbeat to show it is alive. Discord pushes events down that connection, and your code answers them.
So the bot is only online while that program runs. Close your laptop and it goes offline within a minute or so. Hosting a bot 24/7 means running the same program on a computer that never sleeps.
Where to run it
There are three common choices, and the right one depends on how much the bot matters.
| Option | Suits | The catch |
|---|---|---|
| Free tier | Learning and testing | Often sleeps, restarts or needs renewing |
| Bot hosting plan | Most bots | You run the bot, not the whole machine |
| VPS | A bot with a database and website | You look after the operating system |
If your community relies on the bot for moderation, tickets or anything else it would miss, a small paid plan is usually worth it. Rackyard Discord bot plans start at 512 MB of RAM and run Node.js, Python, Bun, Java and Deno.
Prepare the bot
Keep the token out of your code. The token is the bot’s password. Anyone who has it can act as your bot, so read it from an environment variable or a .env file, and add that file to .gitignore. If a token ever reaches a public repository, reset it in the Discord Developer Portal straight away.
List your dependencies. The server has to be able to install what your bot needs, so make sure they are written down rather than only installed on your own computer.
# Node.js: package.json lists them
npm install discord.js
# Python: requirements.txt lists them
python3 -m pip install -U discord.py
pip freeze > requirements.txtTurn on the intents you use. Reading message content, member lists and presence needs privileged intents, which you enable on the Bot page of the Developer Portal as well as in your code. A bot that connects but never reacts to messages is usually missing this.
Check the runtime version. discord.py needs Python 3.8 or newer. discord.js follows current Node.js releases, so check its documentation for the version it asks for.
On a bot hosting plan
The steps are short, because the platform runs the process for you:
- Upload your code, without
node_modulesor a virtual environment. - Set the file that starts the bot, such as
index.jsormain.py. - Add the token as an environment variable or a
.envfile. - Start the server and watch the console until the bot logs in.
On a VPS
On a VPS you keep the bot alive yourself. Running it in an SSH session is not enough, because it stops when you disconnect. A systemd service is the simplest reliable way: it starts the bot at boot and restarts it after a crash. Save this as /etc/systemd/system/mybot.service, with your own user and paths:
[Unit]
Description=My Discord bot
After=network-online.target
Wants=network-online.target
[Service]
User=bot
WorkingDirectory=/home/bot/mybot
EnvironmentFile=/home/bot/mybot/.env
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetFor a Python bot, point ExecStart at your virtual environment’s Python. Then:
sudo systemctl daemon-reload
sudo systemctl enable --now mybot
journalctl -u mybot -fThe last command follows the bot’s logs, which is the first place to look when it misbehaves.
How much RAM does a Discord bot need?
Less than most people expect, until it starts caching a lot of servers or running heavy features. These are the sizes we suggest, and a good starting point on any host:
| RAM | Good for |
|---|---|
| 512 MB | A small bot in a few servers |
| 1 GB | A bot with a database or dashboard |
| 2 GB | A bot in hundreds of servers |
| 3 GB | Music, AI or heavy commands |
| 4 GB | Sharded bots in thousands of servers |
| 6 GB | Several bots, or one big public bot |
| 8 GB | Large public bots running many shards |
Music bots do better with the audio moved out to a separate Lavalink server, which keeps the bot itself small.
As your bot grows
Verification. Discord asks bots to be verified to grow past 100 servers, and access to privileged intents is reviewed at that point too. Start the process before you reach the limit.
Sharding. Each gateway connection can carry at most 2,500 servers, and bots in 2,500 or more must use sharding. Libraries such as discord.js and discord.py manage shards for you, but every shard adds memory, so expect to move to a larger plan.
When it will not stay online
- It logs in, then ignores messages: enable the Message Content intent.
- It restarts repeatedly: read the first error in the console, not the last.
- It dies after hours or days: check for a memory leak, and watch memory over time.
- Invalid token: reset it in the Developer Portal and update the server.
- Rate-limit errors: slow down bulk actions, and let your library queue requests.