Discord Bot

How to Host Your Discord Bot with Python (discord.py)

Host your discord.py bot at Winheberg, token from the Discord portal, Python environment, requirements.txt, .env file, Python version and common errors.

November 2, 2026 Winheberg
Documentation›Discord Bot›How to Host Your Discord Bot with Python (discord.py)

Context

A Discord bot only responds while its program is running. When it runs on your own computer, it goes offline as soon as you shut the computer down or your connection drops. Winheberg Discord bot hosting runs your bot on a server built for this purpose, which you manage from the panel, with a live console, a file manager and a choice of Python versions.

This guide takes as its example a bot written in Python with the discord.py library. You will first create the bot on the Discord developer portal and invite it to your Discord server. Then, on the panel, you will switch the service to the Python environment if needed, upload the bot's code with its token stored in a .env file and choose the Python version, before starting the bot and checking in the console that it is connected.

Is your bot written in JavaScript? See our guide How to Host Your Discord Bot with Node.js (discord.js) instead.

Prerequisites

  • An active Winheberg Discord Bot service, reachable from the panel at https://panel.winheberg.com/
  • A Discord account and a Discord server where you have the Manage Server permission
  • Your bot's code with its requirements.txt file, or the example provided in this guide

1. Create the application and get the token

Go to the Discord developer portal at https://discord.com/developers/applications and log in with your Discord account. Click New Application, give your bot a name, then confirm with Create.

Next, open the application's Bot page. In the Token section, click Reset Token and confirm. Discord then shows your bot's token. Copy it right away, because it is no longer visible once you leave the page, and you would then have to generate a new one.

The token gives full control of your bot. Anyone who has it can use your bot as if it were theirs. Never publish it, whether in a screenshot, a message or a Git repository. If it has leaked, click Reset Token to invalidate it and put the new one in your .env file.

Enable privileged intents if your bot needs them

Still on the Bot page, the Privileged Gateway Intents section groups three kinds of access that Discord does not grant by default. The example bot in this guide uses discord.Intents.default(), which enables none of them. If you use it as is, skip straight to step 2.

Intent in discord.py What it allows
intents.message_content Read message content, for example for prefix commands such as !ping
intents.members Receive the server's member list and member updates
intents.presences See members' status and activity

Only enable in the portal the ones your code sets to True. As long as your application has fewer than 10,000 users, the toggle in the portal is enough.

2. Invite the bot to your Discord server

In the portal, open your application's Installation page. Tick Guild Install under Installation Contexts, then choose Discord Provided Link under Install Link.

Under Default Install Settings, add the applications.commands and bot scopes to Guild Install. The Permissions menu then appears. Select the permissions your bot needs, for example Send Messages and View Channels.

Copy the install link shown on the page, open it in your browser, pick your Discord server and confirm. The bot shows up in the member list, offline until its program runs.

The link generator on the OAuth2 page, in the OAuth2 URL Generator section, works too. Tick the same bot and applications.commands scopes, then copy the generated URL at the bottom of the page.

3. Switch the service to the Python environment

Log in to the Winheberg panel and select your Discord Bot service. In the side menu, click Software Changer. The page lists the available environments, and the active one shows a REINSTALL button instead of INSTALL.

Make a backup before switching environments, especially if the server already holds files you care about.

If python generic is not the active environment, click its INSTALL button, then confirm with Yes.

Software Changer with the python generic environment active and its REINSTALL button

4. Prepare the bot's files

A minimal discord.py bot fits in three files, all placed at the root of the server.

File Purpose
requirements.txt Lists the libraries the bot needs
app.py The bot's code, run at startup
.env The token, kept apart from the code

The requirements.txt file declares discord.py and python-dotenv, the library that reads the .env file.

discord.py>=2.7
python-dotenv>=1.2

The app.py file loads the token, connects the bot and writes a line to the console once the connection is up.

import os

import discord
from dotenv import load_dotenv

load_dotenv()

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


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


client.run(os.getenv("DISCORD_TOKEN"))

The .env file holds a single line, with the token copied in step 1 in place of the sample text.

DISCORD_TOKEN=PASTE_YOUR_BOT_TOKEN_HERE

Do not upload a virtual environment or a library folder. At every start, the server runs pip install -U on the requirements.txt file and installs or upgrades the listed libraries itself.

5. Upload the files to the server

In the side menu, click Files. The Upload button lets you send your files from your computer. Drop them at the root, meaning directly in the folder shown by Files, not in a subfolder.

You can also create each file on the server. Click New file, paste the content into the editor, click Create File, then name the file, requirements.txt in the example below. Do the same for app.py and .env.

requirements.txt file with discord.py and python-dotenv and the Create File button

The three files then show up in the file manager.

.env, app.py and requirements.txt files in the panel file manager

For a large project or many files, use SFTP. Our guide How to Connect to Your Gaming Server via SFTP covers the connection with FileZilla or WinSCP, and it works the same way for a Discord Bot service.

6. Choose the Python version and the main file

In the side menu, click Startup. The Docker Image menu sets the Python version the bot runs on. It offers Python 2.7 as well as versions 3.7 to 3.13.

Startup page with the Python startup command and the Docker Image menu set to Python 3.13

The discord.py 2.7 library requires Python 3.8 or newer, and python-dotenv 1.2 needs Python 3.10 or newer. For the example bot, choose an image from Python 3.10 upwards.

Further down, the Variables section holds the startup settings.

APP PY FILE, ADDITIONAL PYTHON PACKAGES and REQUIREMENTS FILE startup variables
Variable Purpose
APP PY FILE The file run at startup, app.py by default
REQUIREMENTS FILE The file listing the libraries installed at every start, requirements.txt by default
ADDITIONAL PYTHON PACKAGES Extra libraries installed at every start, separated by spaces

If your bot's entry point has another name, bot.py or main.py for example, enter it in APP PY FILE. The panel saves the value as you type it.

Right after going through Software Changer, the APP PY FILE and REQUIREMENTS FILE fields may only show greyed-out sample text. Type the values yourself, app.py and requirements.txt for the example bot.

7. Start the bot and check the console

In the side menu, click Console, then Start. The server shows the Python version, installs the libraries from requirements.txt, then runs app.py.

Python 3.13.18
Collecting discord.py>=2.7 (from -r requirements.txt (line 1))
Collecting python-dotenv>=1.2 (from -r requirements.txt (line 2))
Successfully installed aiohappyeyeballs-2.7.1 aiohttp-3.14.5 aiosignal-1.4.0 attrs-26.1.0 audioop-lts-0.2.2 discord.py-2.7.1 frozenlist-1.8.0 idna-3.20 multidict-7.2.1 propcache-0.5.4 python-dotenv-1.2.4 yarl-1.25.1
2026-11-02 19:29:33 INFO     discord.client logging in using static token

Once the connection to Discord is up, the example bot writes the following line, with your bot's name. The bot then shows as online in your Discord server's member list.

Ready! Logged in as MyBot#1234

On later starts, pip answers Requirement already satisfied for each library already up to date, so the bot starts faster.

If you run into trouble

❌ discord.errors.LoginFailure: Improper token has been passed.

Panel console showing the discord.errors.LoginFailure Improper token has been passed error
  • Check that the file is named exactly .env and sits at the root, next to app.py
  • Check that the variable name is the same in .env and in the code, DISCORD_TOKEN in the example
  • Copy the whole token again, with no space before or after it
  • If you have clicked Reset Token since then, put the new token in .env, the old one no longer works

❌ can't open file '/home/container/bot.py': [Errno 2] No such file or directory

Panel console showing can't open file bot.py No such file or directory
  • The APP PY FILE value does not match any file at the root of the server
  • Open Files and check the exact name of your main file, capital letters included
  • Enter that name in APP PY FILE on the Startup page, then restart

❌ ModuleNotFoundError: No module named 'discord'

  • Check that requirements.txt is at the root and that its name matches the REQUIREMENTS FILE variable
  • Check that it contains the discord.py line, because the code imports the discord module while the library to install is called discord.py
  • Scroll up in the console to the pip lines to spot any install error, then restart

❌ discord.errors.PrivilegedIntentsRequired

The full message starts with Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal.

  • Your code requests a privileged intent, message_content, members or presences, that is not enabled on the developer portal's Bot page
  • Enable the matching intent under Privileged Gateway Intents
  • Or remove the intent your bot does not need from the code, then restart

❌ Prefix commands do not respond

If your bot uses commands.Bot, the console shows the following warning.

Privileged message content intent is missing, commands may not work as expected.
  • Add the line intents.message_content = True to your code before creating the bot
  • Enable the message content intent under Privileged Gateway Intents in the portal, then restart

Best practices

Need help?

If your bot refuses to start or does not connect to Discord despite these checks, our team is here to help. Open a ticket in the Technical department from your client area, fill in the Related Product field with your Discord Bot service and include the error message shown in the console, without ever adding the token.

Your Discord bot is now running on Winheberg 🤖

Need a Bot Discord server?

Discover our offers tailored to your needs and get started now.

View offers