How to host a discord.py bot 24/7
To keep a discord.py bot online 24/7 you need a machine that never sleeps and a supervisor that restarts the process when it dies. HostDC is both, and the free plan does it with a 256 MB RAM pool, 0.5 CPU and 512 MB storage.
1. Prepare the project
Two files are the minimum:
requirements.txt
main.py
requirements.txt:
discord.py>=2.4
main.py:
import os
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
bot.run(os.environ["DISCORD_TOKEN"])
Read the token from the environment instead of a literal in the file. We scrub a token that reaches your output, but you have to rotate one you commit to Git.
2. Upload it
Zip the folder and drop it on the dashboard, or deploy from GitHub if the project already lives there.
3. Add the token and press Deploy
Paste the token on the Secrets tab. Press Deploy, and the console shows the install, then the boot, then your Logged in as line. That line marks the bot healthy.
4. Keep it online
Auto-restart is on by default and backs off between attempts, giving up after 5 crashes in 10 minutes. On Free, reactivate your bots weekly. Paid plans (Mini, Lite, Pro and Max) never need reactivation. See the pricing page.
Related
Last updated 2026-09-06