One-Line Python Fix Stops Telegram and Discord Bots Going Offline on Free Hosting
Developers hosting Telegram or Discord bots on free platforms like Render, Railway, or Koyeb often find their bots silently stop responding within minutes of deployment, despite no errors in the bot's own code. The root cause is that these platforms expect deployed services to expose an HTTP port for health checks, but bots connect outward to external servers and never open one, leading the platform to mark the process as unhealthy and restart it. The fix does not require changing any bot logic; instead, a lightweight HTTP server must run alongside the bot purely to satisfy the platform's health-check requirement. A Python library called StayPresent addresses this in a few lines by starting an HTTP server on the expected port and launching the bot as a managed subprocess. For free tiers that also sleep idle services, the library can additionally ping the app's own public URL on a schedule to simulate incoming traffic and prevent hibernation.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in