Skip to content
Browse documentation

How to host a discord.py bot 24/7

Run a Python Discord bot online around the clock with discord.py: example code, requirements.txt and setup.

discord.py bots stop when your computer sleeps or the terminal closes. Hosted on Marv Hosting, your bot runs on Python 3.12 around the clock and restarts by itself if it crashes.

1. Create the bot in Discord

  1. In the Discord Developer Portal, create a New Application.
  2. Under Bot, click Reset Token and copy the token. Treat it like a password.
  3. Use OAuth2 → URL Generator (scope: bot) to invite the bot to your server.

2. The code

You need a requirements.txt listing your libraries and a main.py. The panel's default start command installs requirements.txt and runs python main.py.

requirements.txt
discord.py
main.py
import os
import discord

intents = discord.Intents.default()
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

client.run(os.environ["DISCORD_TOKEN"])

Keep the token out of main.py — it's read from the DISCORD_TOKEN variable you add in the panel.

3. Upload it

  1. Zip requirements.txt and main.py (no venv or __pycache__ folders).
  2. In the panel, click a free slot, name the bot and choose Python 3.12.
  3. Upload the .zip in the Deploy tab.
  4. Add DISCORD_TOKEN in the Environment tab.

4. Start it

Press Start. The Console shows pip installing discord.py, then "Logged in as …". Output appears live — print() works as you'd expect.

Common problems

  • KeyError: 'DISCORD_TOKEN' — the variable is missing or misspelled in the Environment tab.
  • discord.errors.PrivilegedIntentsRequired — turn on the intents you request (e.g. Message Content) under Bot in the Developer Portal.
  • No module named … — add the library to requirements.txt and restart.