---
title: "How to Host Your Discord Bot with Python (discord.py)"
description: "Host your discord.py bot at Winheberg, token from the Discord portal, Python environment, requirements.txt, .env file, Python version and common errors."
category: cloud
subcategory: bot-discord
icon: tabler:brand-python
date: 2026-11-02
author: Winheberg
slug: "host-discord-bot-python"
order: 168
image: /statics/images/docs/en/cloud/bot-discord/host-discord-bot-python.webp
tags: [discord bot, discord.py, python, panel]
keywords: [host discord bot python, discord bot hosting, discord.py, python discord bot, requirements.txt, discord bot token]
link_fr: "/docs/bot-discord/heberger-bot-discord-python"
---

## 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](https://winheberg.com/en/cloud/discord-bot) 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.

> [!CAUTION]
> 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.

> [!TIP]
> 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**.

> [!WARNING]
> 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**.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644515863-4fda87aa063d51bc1ae0be65.webp" alt="Software Changer with the python generic environment active and its REINSTALL button" width="400" />

## 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.

```bash
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.

```python
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.

```bash
DISCORD_TOKEN=PASTE_YOUR_BOT_TOKEN_HERE
```

> [!IMPORTANT]
> 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`.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644516268-da42faddbde1a554d0c99a8a.webp" alt="requirements.txt file with discord.py and python-dotenv and the Create File button" width="800" />

The three files then show up in the file manager.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644750489-d16393fd263ddf4c6c35138a.webp" alt=".env, app.py and requirements.txt files in the panel file manager" width="800" />

> [!TIP]
> For a large project or many files, use SFTP. Our guide [How to Connect to Your Gaming Server via SFTP](https://winheberg.com/en/docs/panel-gaming/sftp-gaming-server) 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.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644750832-1a7397aada7bd66772ea936d.webp" alt="Startup page with the Python startup command and the Docker Image menu set to Python 3.13" width="800" />

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.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644751193-12f7796bf7ccb1163a40bf00.webp" alt="APP PY FILE, ADDITIONAL PYTHON PACKAGES and REQUIREMENTS FILE startup variables" width="800" />

| 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.

> [!NOTE]
> 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`.

```bash
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.

```bash
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.

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644516634-d83bb0ba4dcb0aa5222f1f94.webp" alt="Panel console showing the discord.errors.LoginFailure Improper token has been passed error" width="640" />

- 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

<img src="/statics/images/docs/en/cloud/bot-discord/host-discord-bot-python-1793644517041-3dcaab4514dc146164f7c19f.webp" alt="Panel console showing can't open file bot.py No such file or directory" width="800" />

- 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.

```bash
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

- **Keep the token in `.env`**, never in `app.py`, and add `.env` to your `.gitignore` if your code is on Git
- **Bound the versions** in `requirements.txt`, for example `discord.py>=2.7,<3`, because at every start the server moves to the latest version within those bounds
- **Make a backup before a major update** of the bot or of discord.py, our guide [How to Create and Restore a Backup of Your Gaming Server](https://winheberg.com/en/docs/panel-gaming/create-restore-backup-gaming-server) explains how
- **Use a MySQL database** if your bot needs to keep data, our guide [How to Create a MySQL Database from the Gaming Panel](https://winheberg.com/en/docs/panel-gaming/create-mysql-database-panel) applies to the Discord Bot service too
- **Give helpers a sub-user account** rather than sharing your password, as explained in our guide [How to Add a Sub-User to Your Gaming Panel](https://winheberg.com/en/docs/panel-gaming/add-sub-user-gaming-panel)

## 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 🤖

