How to host a Python Discord bot
Upload your bot files with a requirements.txt, set your main .py file and Python version in the Startup tab, then click Start and check the console.
- Difficulty:
- Beginner
- Time:
- 10 minutes
On this page
To run a Python bot (discord.py, Pycord, nextcord, a Telegram bot and so on) on Endercloud, upload your code with a requirements.txt file, choose your main .py file and Python version in Startup, and click Start.
Step 1: Create requirements.txt
requirements.txt is a plain text file that lists the packages your bot needs, one per line. The server installs everything in it when the bot starts. Example for a discord.py bot:
discord.py
python-dotenvYou can pin versions if you want the same versions every time, for example discord.py==2.4.0. Use the package names as they appear on PyPI, the name you would type after pip install.
Don't upload a virtual environment folder such as venv or .venv, or __pycache__. They are large and don't work on the server.
Step 2: Upload your files
Open your bot in the Game Panel and go to Files.
Upload your
.pyfiles andrequirements.txtinto the main folder, not inside an extra sub-folder.For many files, upload a
.zipand unarchive it, or use SFTP. See Using the file manager.Store your token in a
.envfile, not in the code. See Keep your bot token safe.
Step 3: Set the main file and Python version
All of the bot's start settings are in the Startup tab. The exact variable names depend on the bot language, so read the description under each one:
Find the variable for the file that starts your bot and enter your file name, for example
main.pyorbot.py. The name must match exactly, including capital letters.If there is a variable for the requirements file, leave it as
requirements.txtunless your file has another name.Pick the Python version in the Docker Image list. Use a version your libraries support; a recent Python 3 release is a safe default for discord.py.
Can't tell which variable is which? Open a ticket and we will point you to the right one.
Step 4: Start and check the console
Click Start and open Console.
The first start installs your packages with pip, which can take a minute. Watch the console to confirm the packages from
requirements.txtare installed.Wait for your bot's "logged in" message and check that it is online in Discord.
Common console errors
Error | What to do |
|---|---|
| Add the package to |
| The main file setting doesn't match your file name, or the file is in a sub-folder. |
| The token is wrong or was reset. Copy a new one from the Discord Developer Portal. |
| Enable the intent your code uses (often Message Content) in the Developer Portal under Bot → Privileged Gateway Intents. |
Syntax errors after changing version | Your code or a package needs a different Python version. Change the Docker Image in Startup and restart. |
If the bot goes offline after running for a while, see My bot keeps going offline.
Frequently asked questions
Do I need to run pip install myself?
Normally no. Packages listed in requirements.txt are installed when the bot starts, so keep the file up to date and restart after changing it. If the console doesn't show pip installing them, check the requirements setting in Startup or open a ticket.
My bot reads messages but the content is empty
Turn on the Message Content intent in the Developer Portal and enable it in your code, for example with intents.message_content = True in discord.py.
Can I switch my bot from Python to Node.js later?
Yes. See Change your bot's language or version.
Was this article helpful?
Related articles
No domain? Open your website, API or bot dashboard over HTTPS with a free SSL certificate from Endercloud. Port first, a dash, then your node name, always on ender.co.in, like https://25808-agni.ender.co.in.
Open Discord Link in the billing panel's user menu and connect your Discord account to get notifications on Discord and the client role in the Endercloud Discord server.
Install DiscordSRV, create a Discord bot with the Server Members and Message Content intents, then put the bot token and channel ID in DiscordSRV's config.yml and restart.
Switch your bot from one language to another with Settings → Change Egg, and change the Node.js, Python or Java version with the Docker Image list in Startup.
