How to keep a Discord bot online 24/7
A bot is only online while a program is running somewhere. Close the terminal and it is gone. These are the real ways to keep it running, including the free ones and the ones that are not us.
7 minute read
Why your bot keeps going offline
A Discord bot is just a program that holds a connection open to Discord. When you run python bot.py on your computer, the bot is online exactly as long as that process is alive. Sleep the laptop, lose Wi-Fi, close the window or restart for an update, and the connection drops.
So "keeping it online 24/7" really means one thing: run the program on a computer that never turns off, and restart it automatically when it crashes. Every option below is a different answer to where that computer is.
Option 1: Your own computer
Fine for development, poor for anything people depend on.
- Cost: free, apart from electricity.
- Catch: it is offline whenever the machine is. Home internet also drops more than people notice, and your home IP address is visible to anything the bot connects to.
Option 2: A Raspberry Pi or old laptop
A genuinely good choice if you like tinkering. A Raspberry Pi uses very little power and can run a small bot for years.
- Cost: the hardware once, then electricity.
- Catch: you are the sysadmin. Power cuts, SD card corruption, updates and your router are all your problem, and there is no backup unless you set one up.
If you go this way, run the bot as a systemd service with Restart=always so it comes back after a crash or reboot.
Option 3: Free hosting tiers
Several platforms offer free plans, and people have long used them for bots. The recurring catch is that free tiers are designed for websites that can go to sleep, not for a program that must hold a connection open.
- Sleeping: many free tiers stop your app after a period without web traffic. A bot receives no web traffic, so it sleeps and goes offline.
- The ping trick: the usual workaround is running a tiny web server inside the bot and having an outside service ping it every few minutes. It often works for a while and tends to break when the platform changes its rules, which several have.
- Limits: monthly hour caps, shared IP addresses that Discord rate-limits, and no promise of uptime.
Good for learning. Frustrating once people rely on your bot.
Option 4: A VPS
A virtual private server is a small Linux machine you rent. It is always on and you control everything.
- Cost: usually a few dollars a month for the smallest sizes.
- Catch: you set up and secure the whole server yourself: SSH keys, a firewall, Python, a service to keep the bot running, updates and backups. Worth learning, but it is real work, and an unpatched VPS is a common way to get compromised.
Option 5: A bot hosting service
Someone else runs the server; you bring the code. You get a console to see output, a file manager, and the bot restarting on crash without you configuring anything.
- Cost: typically a few dollars a month.
- Catch: less control than a VPS, and you are trusting the host with your files and token, so check what they do about backups and security.
Which should you pick?
- Just learning: your own computer, or a free tier.
- You enjoy running servers: a Raspberry Pi or a VPS.
- People use your bot and you want it to just work: a bot host.
Whatever you choose, do these three things
- Keep your token out of your code. Read it from an environment variable. See keeping your bot token safe.
- List your dependencies in a
requirements.txtso the bot installs the same way everywhere. - Restart automatically. Crashes happen. A bot that stays down until you notice is effectively a bot that is offline.
If you want the hosted option
This is what SnowServers does. Python, Node.js or Java, a live console, file manager, SFTP, deploys from GitHub and daily backups, restarted when it crashes. Flurry is $3 a month, and you can try it free for 7 days. Our walkthrough hosting a discord.py bot shows the whole setup.