Many Discord bot developers on free hosting tiers find their bots go offline after exactly 12 hours. This happens because most free hosting providers enforce a session timeout to conserve resources. The bot process is terminated, and the bot appears offline on Discord until the hosting service decides to restart it. This article explains the technical reason behind the 12-hour disconnect, how to identify it, and what you can do to keep your bot online longer.
Key Takeaways: Discord Bot Offline on Free Hosting
- Free hosting session timeout: Providers like Replit and Heroku stop processes after 12 hours of inactivity to save resources.
- Uptime monitoring service: Tools like UptimeRobot or Kaffeine ping your bot every 5 minutes to prevent the idle timeout.
- Paid hosting or self-hosting: Moving to a paid VPS or running the bot on a Raspberry Pi eliminates the 12-hour limit entirely.
Why Free Hosting Tiers Disconnect Bots After 12 Hours
Free hosting platforms such as Replit, Heroku, Glitch, and PythonAnywhere are designed for development and testing. They are not meant for 24/7 production workloads. To keep costs low, these providers automatically stop any process that does not receive a web request or user interaction for a set period. For most free tiers, that period is 12 hours.
When the host stops the bot process, Discord sees the WebSocket connection drop. Discord treats this as the bot going offline. The bot will not automatically reconnect unless the hosting provider restarts it, which may not happen until the next user request or a scheduled wake-up.
Some providers, like Heroku, also put free apps to sleep after 30 minutes of inactivity. However, bots that maintain a constant WebSocket connection are considered inactive if they do not handle incoming HTTP requests. This distinction is the root cause of the 12-hour offline issue.
How the Idle Timeout Works
The idle timeout is enforced by the hosting platform’s process manager. It checks the last time the bot process sent or received data. If no data passes for the timeout duration, the process receives a SIGTERM signal. The bot shuts down without warning. The platform then marks the app as sleeping. The bot stays offline until a new HTTP request triggers a restart.
Why 12 Hours Specifically
The 12-hour limit is a common default across free tiers. It balances resource usage with user expectations. A 12-hour session allows developers to test bots during a workday without constant restarts, but it prevents long-running bots from consuming free resources overnight.
Steps to Keep Your Discord Bot Online Beyond 12 Hours
You have three main options to prevent the 12-hour disconnect. Each method works differently, and the best choice depends on your budget and technical comfort.
Method 1: Use an Uptime Monitoring Service
Uptime monitoring services send periodic HTTP requests to your bot’s web server endpoint. This tricks the free hosting platform into thinking the bot is active. The bot stays awake because it receives a request every few minutes.
- Add a simple web server to your bot
If your bot does not already run an HTTP server, add one. In Python with discord.py, use Flask or FastAPI. In Node.js with discord.js, use Express. The server only needs to respond to a GET request with a 200 status code. - Deploy the bot to your free hosting provider
Push your code and start the bot normally. Confirm the bot appears online in your Discord server. - Sign up for a free uptime monitoring service
Services like UptimeRobot (free tier: 5 monitors), Kaffeine (for Heroku), or Better Uptime offer free plans. Create an account and add a new monitor. - Configure the monitor to ping your bot’s URL
Enter the full URL of your bot’s web server endpoint (for example, https://your-bot-name.herokuapp.com/). Set the check interval to 5 minutes. Save the monitor. - Verify the bot stays online
Wait 12 hours and check if the bot is still online. The monitor will send a ping every 5 minutes, resetting the idle timer each time.
Method 2: Upgrade to a Paid Hosting Plan
Paid plans from the same providers remove the idle timeout entirely. Heroku Hobby tier ($7 per month) keeps apps awake. Replit Hacker plan ($7 per month) allows always-on repls. PythonAnywhere paid accounts have no sleep timeout. This is the most reliable method for production bots.
- Choose a paid plan that fits your budget
Compare prices and features. Heroku Hobby is popular for small bots. Replit Hacker offers always-on for one repl. - Upgrade your account
Go to the billing section of your hosting provider and select the paid plan. Enter payment details. - Enable the always-on or no-sleep option
For Heroku, no extra configuration is needed. For Replit, toggle the always-on switch in the repl settings. For PythonAnywhere, the always-on option is in the web app settings. - Restart the bot
Stop and start the bot process. Confirm it stays online for more than 12 hours.
Method 3: Self-Host on a Raspberry Pi or Old Computer
Self-hosting gives you full control. A Raspberry Pi 4 running 24/7 costs about $5 per year in electricity. You can run the bot using a process manager like PM2 or systemd that restarts it automatically if it crashes.
- Install the required software on the device
Set up Python or Node.js. Install Git to clone your bot repository. - Clone your bot code to the device
Use git clone or copy the files manually. Install dependencies with pip or npm. - Configure a process manager
Install PM2 for Node.js or use systemd for Python. Create a configuration that starts the bot on boot and restarts it if it stops. - Test the bot runs beyond 12 hours
Leave the device powered on and connected to the internet. Check the bot status after 12 hours.
If Your Bot Still Goes Offline After These Fixes
Bot Goes Offline After 24 Hours Instead of 12
Some hosting providers have a longer idle timeout. For example, Glitch puts apps to sleep after 5 days of inactivity. However, their free tier also limits CPU hours per month. If your bot uses too many CPU hours, it will be throttled and may appear offline. Check your usage dashboard.
Bot Goes Offline Randomly, Not Exactly at 12 Hours
This usually indicates a crash caused by an unhandled exception or memory leak. Check the bot’s logs. Look for error messages. Use try/except blocks to catch errors gracefully. Add a crash handler that logs the error and restarts the bot.
Uptime Monitor Shows Bot Online, But Discord Shows Offline
This happens when the WebSocket connection drops but the HTTP server remains running. The uptime monitor only checks the HTTP endpoint, not the Discord connection. Add a health check endpoint that verifies the bot is connected to Discord. If the bot is not connected, restart the WebSocket client.
Free Hosting Tiers Comparison for Discord Bots
| Feature | Replit Free | Heroku Free |
|---|---|---|
| Idle timeout | 12 hours | 30 minutes to 12 hours |
| Workaround needed | Uptime monitor or always-on paid plan | Uptime monitor or paid plan |
| Cost to remove timeout | $7/month (Hacker plan) | $7/month (Hobby plan) |
| CPU limits | Shared CPU, throttled after heavy use | 550 hours/month free |
| Best for | Small bots with low traffic | Bots that need a web server |
The 12-hour offline issue on free hosting tiers is caused by idle timeouts enforced by providers to save resources. Using an uptime monitor, upgrading to a paid plan, or self-hosting are the three reliable ways to keep your bot online. For production bots, a paid plan or self-hosting is recommended because uptime monitors can still fail if the hosting provider changes its policy. Start by adding an uptime monitor today to see if it solves the problem before investing in a paid plan.