{"id":4452,"date":"2026-08-20T03:43:31","date_gmt":"2026-08-20T03:43:31","guid":{"rendered":"https:\/\/tucumandevelopers.com\/index.php\/2026\/08\/20\/how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier\/"},"modified":"2026-08-20T03:43:31","modified_gmt":"2026-08-20T03:43:31","slug":"how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier","status":"publish","type":"post","link":"https:\/\/tucumandevelopers.com\/index.php\/2026\/08\/20\/how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier\/","title":{"rendered":"How to Stop Your Discord Bot From Sleeping on Render&#8217;s Free Tier"},"content":{"rendered":"<div>\n<div>\n<div data-article-id=\"4439649\" id=\"article-body\">\n<blockquote>\n<p>A step-by-step tutorial to stop a discord bot from sleeping on Render&#8217;s free tier \u2014 the real cause, the fix, and a working code example.<\/p>\n<\/blockquote>\n<h2> <a name=\"how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier\" href=\"#how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier\"> <\/a> How to Stop Your Discord Bot From Sleeping on Render&#8217;s Free Tier <\/h2>\n<p>You&#8217;ve deployed your Discord bot to Render&#8217;s free tier, it worked for a bit, and now it&#8217;s going offline \u2014 sometimes after a few minutes, sometimes randomly. This is one of the most common issues developers hit deploying a bot for the first time, and it has a specific, well-understood cause and a fix you can ship in under ten minutes.<\/p>\n<h2> <a name=\"table-of-contents\" href=\"#table-of-contents\"> <\/a> Table of Contents <\/h2>\n<ol>\n<li>Why This Happens on Render Specifically<\/li>\n<li>Confirming This Is Your Actual Problem<\/li>\n<li>Step 1: Install StayPresent<\/li>\n<li>Step 2: Wrap Your Bot&#8217;s Entry Point<\/li>\n<li>Step 3: Read Render&#8217;s Assigned Port<\/li>\n<li>Step 4: Set Your Render Start Command<\/li>\n<li>Step 5 (Optional): Prevent Inactivity Sleep Specifically<\/li>\n<li>Verifying It Worked<\/li>\n<li>FAQs<\/li>\n<li>Conclusion<\/li>\n<\/ol>\n<h2> <a name=\"why-this-happens-on-render-specifically\" href=\"#why-this-happens-on-render-specifically\"> <\/a> Why This Happens on Render Specifically <\/h2>\n<p>Render&#8217;s free-tier web services are checked for health over HTTP, and free services also spin down after a period without incoming traffic. A discord.py bot connects <em>outward<\/em> to Discord&#8217;s gateway \u2014 it never opens an HTTP port of its own, which is completely normal bot behavior. Render&#8217;s health checker, seeing nothing respond on the expected port, has no way to know the bot is actually working fine internally. It just sees silence, and reacts accordingly.<\/p>\n<h2> <a name=\"confirming-this-is-your-actual-problem\" href=\"#confirming-this-is-your-actual-problem\"> <\/a> Confirming This Is Your Actual Problem <\/h2>\n<p>If your bot&#8217;s entry point goes straight into <code>bot.run(TOKEN)<\/code> with nothing else, and Render&#8217;s dashboard shows the deployment as unhealthy or repeatedly restarting with no matching error in your bot&#8217;s own logs, this is almost certainly it.<\/p>\n<h2> <a name=\"step-1-install-staypresent\" href=\"#step-1-install-staypresent\"> <\/a> Step 1: Install StayPresent <\/h2>\n<div>\n<pre><code>pip <span>install <\/span>staypresent[prod] <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<p>Add it to your <code>requirements.txt<\/code> as well: <\/p>\n<div>\n<pre><code>staypresent[prod] discord.py <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<h2> <a name=\"step-2-wrap-your-bots-entry-point\" href=\"#step-2-wrap-your-bots-entry-point\"> <\/a> Step 2: Wrap Your Bot&#8217;s Entry Point <\/h2>\n<p>Keep your existing bot code in <code>bot.py<\/code> completely unchanged. Create a new <code>main.py<\/code>: <\/p>\n<div>\n<pre><code><span>import<\/span> <span>os<\/span> <span>import<\/span> <span>staypresent<\/span> <span>staypresent<\/span><span>.<\/span><span>web<\/span><span>.<\/span><span>json<\/span><span>({<\/span><span>\"<\/span><span>status<\/span><span>\"<\/span><span>:<\/span> <span>\"<\/span><span>running<\/span><span>\"<\/span><span>})<\/span> <span>staypresent<\/span><span>.<\/span><span>run<\/span><span>(<\/span><span>\"<\/span><span>bot.py<\/span><span>\"<\/span><span>)<\/span> <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<h2> <a name=\"step-3-read-renders-assigned-port\" href=\"#step-3-read-renders-assigned-port\"> <\/a> Step 3: Read Render&#8217;s Assigned Port <\/h2>\n<p>Render injects a <code>PORT<\/code> environment variable \u2014 your app needs to bind to it dynamically, not a hardcoded value: <\/p>\n<div>\n<pre><code><span>import<\/span> <span>os<\/span> <span>import<\/span> <span>staypresent<\/span> <span>staypresent<\/span><span>.<\/span><span>web<\/span><span>.<\/span><span>json<\/span><span>({<\/span><span>\"<\/span><span>status<\/span><span>\"<\/span><span>:<\/span> <span>\"<\/span><span>running<\/span><span>\"<\/span><span>})<\/span> <span>staypresent<\/span><span>.<\/span><span>run<\/span><span>(<\/span> <span>\"<\/span><span>bot.py<\/span><span>\"<\/span><span>,<\/span> <span>port<\/span><span>=<\/span><span>int<\/span><span>(<\/span><span>os<\/span><span>.<\/span><span>getenv<\/span><span>(<\/span><span>\"<\/span><span>PORT<\/span><span>\"<\/span><span>,<\/span> <span>8080<\/span><span>)),<\/span> <span>)<\/span> <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<h2> <a name=\"step-4-set-your-render-start-command\" href=\"#step-4-set-your-render-start-command\"> <\/a> Step 4: Set Your Render Start Command <\/h2>\n<p>In Render&#8217;s service settings, set the start command to run your new entry point: <\/p>\n<div>\n<pre><code>python main.py <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<p>Deploy. Render now has something to check on, and your bot&#8217;s own logic \u2014 the actual discord.py code \u2014 didn&#8217;t change at all.<\/p>\n<h2> <a name=\"step-5-optional-prevent-inactivity-sleep-specifically\" href=\"#step-5-optional-prevent-inactivity-sleep-specifically\"> <\/a> Step 5 (Optional): Prevent Inactivity Sleep Specifically <\/h2>\n<p>Solving the port requirement alone stops Render from marking the deployment unhealthy. If Render&#8217;s free tier is <em>also<\/em> spinning your specific service down after inactivity, add a self-ping targeting your own public URL: <\/p>\n<div>\n<pre><code><span>import<\/span> <span>os<\/span> <span>import<\/span> <span>staypresent<\/span> <span>staypresent<\/span><span>.<\/span><span>web<\/span><span>.<\/span><span>json<\/span><span>({<\/span><span>\"<\/span><span>status<\/span><span>\"<\/span><span>:<\/span> <span>\"<\/span><span>running<\/span><span>\"<\/span><span>})<\/span> <span>staypresent<\/span><span>.<\/span><span>cron<\/span><span>(<\/span><span>\"<\/span><span>https:\/\/your-app-name.onrender.com<\/span><span>\"<\/span><span>,<\/span> <span>interval<\/span><span>=<\/span><span>240<\/span><span>)<\/span> <span>staypresent<\/span><span>.<\/span><span>run<\/span><span>(<\/span> <span>\"<\/span><span>bot.py<\/span><span>\"<\/span><span>,<\/span> <span>port<\/span><span>=<\/span><span>int<\/span><span>(<\/span><span>os<\/span><span>.<\/span><span>getenv<\/span><span>(<\/span><span>\"<\/span><span>PORT<\/span><span>\"<\/span><span>,<\/span> <span>8080<\/span><span>)),<\/span> <span>)<\/span> <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<p>This has to target your actual <code>onrender.com<\/code> URL \u2014 pinging <code>0.0.0.0<\/code> or <code>127.0.0.1<\/code> never leaves the machine and won&#8217;t count as external activity.<\/p>\n<h2> <a name=\"verifying-it-worked\" href=\"#verifying-it-worked\"> <\/a> Verifying It Worked <\/h2>\n<p>After deploying, check Render&#8217;s dashboard \u2014 the service should show as healthy rather than restarting in a loop. You can also visit your app&#8217;s <code>\/health<\/code> endpoint directly in a browser; it should return <code>{\"status\": \"ok\"}<\/code>. If you&#8217;re on a recent version of StayPresent, <code>\/status<\/code> shows a live status page with uptime history, which is a quick way to confirm the bot is staying up over time rather than just checking once.<\/p>\n<h2> <a name=\"faqs\" href=\"#faqs\"> <\/a> FAQs <\/h2>\n<p><strong>Do I need to change my bot&#8217;s actual Discord logic?<\/strong><br \/> No \u2014 <code>bot.py<\/code> stays exactly as it was. Only the entry point Render runs (<code>main.py<\/code>) is new.<\/p>\n<p><strong>Does this work for Telegram bots too?<\/strong><br \/> Yes \u2014 the same pattern applies to any long-running Python process that doesn&#8217;t open its own HTTP port, regardless of which platform&#8217;s API it talks to.<\/p>\n<p><strong>Will this cost anything?<\/strong><br \/> No \u2014 StayPresent is MIT licensed and free, and this setup doesn&#8217;t require upgrading your Render plan.<\/p>\n<h2> <a name=\"conclusion\" href=\"#conclusion\"> <\/a> Conclusion <\/h2>\n<p>A Discord bot sleeping on Render&#8217;s free tier is almost always a missing HTTP port, not a bug in your bot. Wrapping your existing <code>bot.py<\/code> in <code>staypresent.run()<\/code>, reading Render&#8217;s <code>PORT<\/code> variable, and optionally self-pinging your public URL solves it completely, with zero changes to your bot&#8217;s actual code. <\/p>\n<div>\n<pre><code>pip <span>install <\/span>staypresent[prod] <\/code><\/pre>\n<div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Fuente: <a href=\"https:\/\/dev.to\/codenamew\/how-to-stop-your-discord-bot-from-sleeping-on-renders-free-tier-4aca\">Art\u00edculo original<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A step-by-step tutorial to stop a discord bot from sleeping on Render&#8217;s free tier \u2014 the real cause, the fix, and a working code example. How to Stop Your Discord Bot From Sleeping on Render&#8217;s Free Tier You&#8217;ve deployed your Discord bot to Render&#8217;s free tier, it worked for a bit, and now it&#8217;s going [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4451,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"webixso_pending_account_ids":""},"categories":[41],"tags":[],"class_list":["post-4452","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devto"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/4452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/comments?post=4452"}],"version-history":[{"count":0,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/4452\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media\/4451"}],"wp:attachment":[{"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/media?parent=4452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/categories?post=4452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tucumandevelopers.com\/index.php\/wp-json\/wp\/v2\/tags?post=4452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}