How to keep a Discord bot online 24/7:
self-hosting or a bot host
A bot is online only while its program is running and connected to Discord. You can run that program on your own computer, a free platform or a bot host, and what separates them is whether it can stay on around the clock.
Why bots go offline
- The computer shuts down or sleeps, or someone closes the window running the program.
- The program crashes and nobody restarts it.
- A free platform sees no traffic and puts the program to sleep.
A server that stays on takes care of shutdowns and sleeping. A crashed program still goes offline, though, so you need to know when it stops.
Where to run the code
| Compared | Your own PC | Free platform | Bot hosting |
|---|---|---|---|
| Cost | Electricity | Free | from NT$29/mo |
| Uptime | Only while the PC is on | May sleep or queue | 24/7 |
| Memory | Depends on your PC | Small, often capped | 512 MB to 2 GB |
| Outbound IP | Your home IP | Often shared by many users | Shared with other bots, dedicated outbound IP available as an add-on |
| Updating code | Edit and restart | Depends on the platform | Upload files or push to GitHub |
While a bot is still in development or testing, running it on your own computer is fine. A free platform can work for a small bot that tolerates some downtime, as long as you keep an eye on sleep rules and resource limits. Bot hosting is for bots that need to stay online 24/7, written in JavaScript, Python, Java or Go.
Token and permissions
The token is generated when you create the bot in the Developer Portal. Anyone who has it can fully control your bot, so guard it like a password.
- Keep the token in a config file such as
.env, never in the code itself. - Before pushing to GitHub, add
.envto.gitignore, because anyone can see every file in a public repository. - To read the text of regular messages, turn on Message Content Intent in the Developer Portal and set the intents in your code.
Set up on a bot host
1. Choose a plan
| Plan | Memory | CPU | Storage | Monthly |
|---|---|---|---|---|
| DCB-A | 512 MB | 1 core | 10 GB | NT$29 |
| DCB-B | 768 MB | 1 core | 15 GB | NT$39 |
| DCB-C | 1 GB | 1.5 cores | 20 GB | NT$49 |
| DCB-D | 2 GB | 2 cores | 50 GB | NT$99 |
Hosted in the United States on AMD EPYC. Prices in New Taiwan dollars (TWD), billed every 30 days.
2. Go live with the Setup wizard
The Setup wizard in vPanel has 5 steps.
- Code source: put your bot's files on the server.
- Main file: the file to run at startup, such as
index.jsorapp.py. - Version: the runtime version, such as Python 3.13.
- Token: if there is no
.env, the wizard creates an empty template. Open.envin Files and paste your token afterDISCORD_TOKEN=. The wizard does not fill in the token for you, and it does not read a.envthat already exists. - Start: installs packages, then runs the main file.
If the console shows Improper token or a 401 error, the token is wrong. Check .env for extra spaces or quotation marks copied along with it.
3. Manage packages
A Node.js bot lists its packages in package.json, and npm install runs on every start. To add a package, enter its name and version under Packages.
4. Auto-update from GitHub
Once you link a GitHub repository and branch, the bot pulls the latest code each time it restarts. With the GitHub webhook turned on, a push to the tracked branch makes the bot pull and restart in about 10 seconds.
5. Get notified when it crashes
As long as you didn't stop it yourself, Alerts sends a message to your Discord webhook or Telegram whenever the bot goes down. The reason for the crash shows up as an error in the console.
References
- Gateway Discord Developer Docs
- Bots & Companion Apps Discord Developer Docs