How do I host a Python bot?
Prepare requirements.txt, choose the main file and install the dependencies. The Python environment uses a dependency file and an explicit launch command.
The Python environment uses a dependency file and an explicit launch command. Avoid storing the token directly in code.
Step-by-step procedure
-
Prepare requirements.txt
List the necessary libraries with compatible versions.
-
Choose the Python environment
Order a bot and select the Python environment offered in the catalog.
-
Import the code
Upload requirements.txt, the source folder and the main file.
-
Configure secrets
Create the DISCORD_TOKEN variable, then read it with os.environ.
-
Start
Click “Start”: the platform installs requirements.txt, then runs python -u bot.py or the “Main file” set in Startup.
requirements.txt
discord.py==2.5.2
python-dotenv==1.1.0
Reading the token
import os
TOKEN = os.environ["DISCORD_TOKEN"]
Minimal bot.py file
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"])
Before you start
Choose the Python version closest to the one on your computer: 3.11, 3.12 or 3.13. You can change it later in the “Startup” tab, “Docker image” card, and the dependencies are then reinstalled.
- A requirements.txt at the root, with pinned versions such as discord.py==2.5.2.
- Otherwise, the dependencies of the [project] section of pyproject.toml are installed.
- A main file at the root, for example bot.py or main.py.
- No venv or .venv folder in the upload: the platform installs its own packages.
How the bot is launched
At start, the platform installs the packages from requirements.txt if they changed since the last installation, then runs the main file with python -u. The -u option turns off output buffering: your print() calls appear in the console right away.
Without any setting, the file run is the first one found among bot.py, main.py, app.py, run.py and index.py. For another file, fill in the “Main file” in “Startup”. A different dependency file name is set with the “Requirements file”.
Packages are installed from prebuilt versions (wheels) first. A package without a compatible wheel is built from source, which takes longer and can fail: in that case choose a more recent version of the package.
Check that everything works
Add a message in the on_ready event, start the bot and open the console. The command line, for example $ python -u bot.py, should be followed by your login message. If the bot keeps restarting, the first Python error is right above the line that reports the process exit.
Frequently asked questions
What should I do about ModuleNotFoundError: No module named 'discord'?
The package is missing from requirements.txt or its installation failed. The installed name differs from the imported one: the code says import discord, but the package is called discord.py. Add the line, then restart: the installation runs again at start.
Why No module named 'audioop' with Python 3.13?
The audioop module was removed in Python 3.13 and older versions of discord.py still import it. Update discord.py in requirements.txt or add the audioop-lts package, then restart.
What does discord.errors.LoginFailure: Improper token has been passed. mean?
Discord rejects the token it received. Check that the variable is named exactly DISCORD_TOKEN in “Startup” and that it holds the token from the “Bot” tab, not the client secret. If the token may have leaked, regenerate it with “Reset Token”, save the new value and restart.
The bot stops with PrivilegedIntentsRequired, what should I do?
The code enables message_content, members or presences while the intent is not allowed for the application. Enable it in the Discord portal, “Bot” tab, “Privileged Gateway Intents” section, then restart the bot.