PYTHON · DISCORD.PY

Deploy a Python Discord bot

Package a discord.py bot with explicit dependencies, a single startup command and secrets kept out of source files.

6 min readBeta documentation
Before you start
  • A working Discord application and bot user
  • A Python project using discord.py
  • A requirements.txt committed or included in the ZIP
  • No .env file containing a live token

1. Declare Python dependencies

Use requirements.txt for the initial Botkeep runtime. Pin a compatible range rather than depending on whatever happens to be newest when the bot is rebuilt.

requirements.txtexample
discord.py>=2.4,<3.0

2. Use one explicit entry point

A simple main.py keeps detection and troubleshooting predictable. Choose one of the Python versions currently offered in the creation form.

main.pyexample
import os
import discord

token = os.environ.get("DISCORD_TOKEN")
if not token:
    raise RuntimeError("DISCORD_TOKEN is required")

class BotClient(discord.Client):
    async def on_ready(self):
        print(f"Connected as {self.user}")

client = BotClient(intents=discord.Intents.default())
client.run(token)

3. Make the process container-friendly

  • Use python main.py as a direct, non-interactive start command.
  • Send diagnostic output to stdout and stderr.
  • Do not depend on files outside the project root.
  • Do not assume root access, system package installation or public ports.

4. Confirm the Botkeep settings

Choose Python, select the repository or ZIP, confirm python main.py and add DISCORD_TOKEN as a secret. If a dependency requires a native system library, verify that it is supported before deploying.

Continue readingDeploy from GitHub