Keeping a Discord bot online 24/7: a checklist

2026-11-28来源 dev.toEnglish

Your bot works on your laptop. Then you close the lid and it goes offline. Here is what a bot needs to stay up, whichever host you use.

1. Somewhere that is always on. A spare PC works until a Windows update reboots it. A VPS works if you are happy to manage Linux. A bot host is the least work.

2. Restart on crash. Bots crash: an unhandled promise rejection, a rate limit, a Discord gateway hiccup. Run the bot under something that restarts it (systemd with Restart=on-failure, pm2 for Node, or your host's crash detection), with a backoff so a crash loop does not hammer Discord's API.

3. Keep the token out of your code. Put DISCORD_TOKEN in a .env file, add .env to .gitignore, and read it with process.env or os.environ. If a token ever lands in a public repo, reset it in the Developer Portal straight away.

4. Ask for the right intents. Privileged intents (Message Content, Server Members, Presence) must be switched on in the Developer Portal as well as in your code, or the bot connects and then sees nothing.

5. Logs you can read later. When the bot dies at 3am you want the stack trace. Log to a file or a host console you can search.

6. Deploy without SSH. Pulling from a Git repo beats copying files by hand, and makes rolling back easy.

7. Enough memory, not too much. A small discord.js or discord.py bot usually fits in 256 to 512 MB. Music bots and big caches need more.

If you would rather not manage any of that yourself: we run Discord bot hosting at Zeros Host from £1 a month. It supports Node.js, Python, TypeScript, Java, Go and Rust, deploys from GitHub, keeps your token masked, and restarts the bot on a crash. There is a free 48 hour trial, no card needed: https://zerosrp.co.uk/discord-bot

原文:https://www.a8q9.cn/en/article/keeping-a-discord-bot-online-24-7-a-checklist-a18a97.html

相关文章