The Python template runs Python 3.12/3.13. On start it installs requirements.txt when the packages are missing or the file has changed, then runs your main file.
Deploy in four steps
- Upload
main.py,requirements.txt, and any cogs or modules in the file manager or over SFTP. Don't upload a virtualenv folder. - If your entry file has another name, such as
bot.py, set Main file (MAIN_FILE) to it. The default ismain.py. - Paste your token into Bot token (
BOT_TOKEN), and read it in code withos.environ["BOT_TOKEN"]. - Restart and wait for
BOT_READYin the console.
A minimal bot
discord.py==2.5.2import os
import discord
from discord import app_commands
client = discord.Client(intents=discord.Intents.default())
tree = app_commands.CommandTree(client)
@tree.command(name="ping", description="Replies with pong")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message("pong")
@client.event
async def on_ready():
await tree.sync()
print("BOT_READY", flush=True)
client.run(os.environ["BOT_TOKEN"])Python buffers output when it isn't writing to a terminal. Use print(..., flush=True) or the logging module, or the ready line may not reach the console in time.
What runs on start
# if the main file is missing, the start stops here
# only when the packages are missing or requirements.txt changed
$ pip install --upgrade --target .python-deps -r requirements.txt
$ python main.py
BOT_READYList every package the bot imports in requirements.txt, including discord.py itself, and pin versions with == so a restart doesn't pull a surprise upgrade. A module-not-found error almost always means a package is missing from that file or misspelled. Packages go into the .python-deps folder, so leave it in place.
Libraries such as discord.py-self and selfcord automate a user account, which breaks Discord's terms. A server running one is suspended.
Deploy from GitHub
On Free (public repositories) and paid plans, set Git repository (GIT_REPO) and Git branch (GIT_BRANCH), set Auto update (AUTO_UPDATE) to 1, and restart. Private repositories use Git token (GIT_TOKEN). The first start clones the repository without deleting anything: files with the same names as files in the repository move to a pre-git-backup- folder. Every later start fetches the branch and resets tracked files, so edits made on the server are overwritten. Reinstall keeps existing files and defers the repository fetch to the next start with Auto update on. How to get backed-up files back and how to reinstall are covered in deploy discord.js. Free public deploys must fit the free disk limit; private repositories need a paid plan. If the bot starts but doesn't answer, see troubleshooting.
Still stuck? Contact support