Use a Python bot host with an always-on process
Upload your bot to a host that keeps a Python process running and installs packages from requirements.txt. On Bothosting, choose the discord.py profile, upload main.py and requirements.txt, save the token as BOT_TOKEN and start it. Spark runs it for free with 256 MB RAM, renewed every 7 days. Paid plans start at $2.25 a month with no renewal.
Lay out the project
main.py
requirements.txt
cogs/
moderation.pydiscord.py>=2.4import os
import discord
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print(f'Logged in as {client.user}', flush=True)
client.run(os.environ['BOT_TOKEN'])Start it and prove it runs without you
- Create a deployment with the discord.py profile and upload the files to the root.
- Save the token from the Discord Developer Portal as
BOT_TOKENin Variables. - Start the deployment. Console should show
Logged in asfollowed by your bot’s name. - Stop any copy running on your PC, close the laptop and run a command from your phone.
Using flush=True makes prints appear in Console immediately. See why Python logs appear all at once.
Keep data across restarts
Files the bot writes to its own directory persist across restarts, so SQLite works for per-server settings. Use a database deployment when several processes need the same data. See SQLite in a hosted Python bot. To deploy every push, connect a GitHub branch.