# How to Install a Python Discord Bot (/docs/discord-bots/install-python-bot)



import { Step, Steps } from 'fumadocs-ui/components/steps';

This guide covers how to deploy a Python Discord bot (such as one built with [discord.py](https://discordpy.readthedocs.io/)) on your XGamingServer.

> 📝 **Note:** You need a Discord bot token before proceeding. If you have not created one yet, follow our [Create a Bot Token](/docs/discord-bots/create-bot-token) guide first.

Check your `Startup` page to see which server type you have. If you see **App py File**, **Git Repo Address**, and **User Uploaded Files** variables, follow the [Standalone Python Server](#standalone-python-server) instructions. If you only see a **Startup Command** variable, follow the [Discord Bot Server](#discord-bot-server) instructions.

***

Standalone Python Server [#standalone-python-server]

If your `Startup` page has **App py File**, **Git Repo Address**, **User Uploaded Files**, and **Additional Python Packages** variables, you have the standalone Python egg. Dependencies install automatically from `requirements.txt` on each start.

Option A: Upload Files [#option-a-upload-files]

<div className="fd-steps">
  <div className="fd-step">
    Enable User Uploads [#1-enable-user-uploads]

    Go to `Startup` and set **User Uploaded Files** to `1`. This skips the Git clone step on startup.
  </div>

  <div className="fd-step">
    Upload Your Bot Files [#2-upload-your-bot-files]

    Log in to the [XGamingServer panel](https://panel.xgamingserver.com) and go to the `Files` page. Upload your bot files including:

    * Your main bot file (e.g., `bot.py`, `main.py`)
    * `requirements.txt` with your Python dependencies listed
    * Any other files your bot needs (cogs folder, config files, etc.)
  </div>

  <div className="fd-step">
    Set the App py File [#3-set-the-app-py-file]

    Go to `Startup` and set **App py File** to your bot's main file:

    ```
    bot.py
    ```

    Replace `bot.py` with your actual main file name. The default is `app.py`.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#4-configure-your-bot-token]

    Go to `Files` and create a `.env` file with your bot token:

    ```
    TOKEN=your_bot_token_here
    ```

    Use whatever variable name your bot's code expects. See our [Manage Bot Token](/docs/discord-bots/manage-bot-token) guide for more details.
  </div>

  <div className="fd-step">
    Start Your Server [#5-start-your-server]

    Go to the `Console` page and click **Start**. The server will automatically install packages from `requirements.txt` and then run your bot.
  </div>
</div>

Option B: Deploy from GitHub [#option-b-deploy-from-github]

<div className="fd-steps">
  <div className="fd-step">
    Set the Git Repository [#1-set-the-git-repository]

    Go to `Startup` and fill in:

    * **Git Repo Address** — Your repository URL (e.g., `https://github.com/username/my-bot`)
    * **Git Branch** — The branch to clone (leave blank for the repo default)
    * **User Uploaded Files** — Set to `0` (so the server clones from Git)
  </div>

  <div className="fd-step">
    Set the App py File [#2-set-the-app-py-file]

    Set **App py File** to your bot's main file (e.g., `bot.py`).
  </div>

  <div className="fd-step">
    Enable Auto Update (Optional) [#3-enable-auto-update-optional]

    Set **Auto Update** to `1` if you want the server to pull the latest code from GitHub on each restart.
  </div>

  <div className="fd-step">
    Start Your Server [#4-start-your-server]

    Go to `Console` and click **Start**. The server will clone the repo, install dependencies, and run your bot.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#5-configure-your-bot-token]

    After the first start, go to `Files` and create a `.env` file with your bot token. The repository is cloned to the server's file directory. Restart for the token to take effect.
  </div>
</div>

Installing Additional Packages [#installing-additional-packages]

If you need packages beyond what is in `requirements.txt`, add them to the **Additional Python Packages** field on the `Startup` page (space-separated):

```
aiohttp pillow
```

These packages are installed automatically alongside your `requirements.txt` dependencies on each start.

Custom Requirements File [#custom-requirements-file]

If your project uses a different filename for requirements (e.g., `requirements-bot.txt`), set the **Requirements File** variable on the `Startup` page to match.

Using a Private GitHub Repository [#using-a-private-github-repository]

On the `Startup` page, fill in the **Git Username** and **Git Access Token** fields. Create a [personal access token](https://github.com/settings/tokens) with `repo` scope and use it as the access token.

***

Discord Bot Server [#discord-bot-server]

If your `Startup` page only has a **Startup Command** variable, you have the multi-language Discord Bot server.

> 📝 **Note:** Make sure your server is using a Python Docker image. If your server was set up for Node.js, contact support or join our [Discord](https://discord.xgamingserver.com) to switch to a Python image.

<div className="fd-steps">
  <div className="fd-step">
    Upload Your Bot Files [#1-upload-your-bot-files]

    Log in to the [XGamingServer panel](https://panel.xgamingserver.com) and go to the `Files` page. Upload your bot files including:

    * Your main bot file (e.g., `bot.py`, `main.py`)
    * `requirements.txt` with your Python dependencies listed
    * Any other files your bot needs (cogs folder, config files, etc.)
  </div>

  <div className="fd-step">
    Install Dependencies [#2-install-dependencies]

    Go to `Startup` and set the **Startup Command** to:

    ```
    /bin/bash
    ```

    Start the server. In the `Console`, type:

    ```
    pip3 install -r requirements.txt
    ```

    Wait for all dependencies to install.
  </div>

  <div className="fd-step">
    Configure Your Bot Token [#3-configure-your-bot-token]

    Go to `Files` and create a `.env` file with your bot token:

    ```
    TOKEN=your_bot_token_here
    ```

    Use whatever variable name your bot's code expects. See our [Manage Bot Token](/docs/discord-bots/manage-bot-token) guide for more details.
  </div>

  <div className="fd-step">
    Set the Startup Command [#4-set-the-startup-command]

    Go to `Startup` and change the **Startup Command** to run your bot:

    ```
    python3 bot.py
    ```

    Replace `bot.py` with your bot's main file name.
  </div>

  <div className="fd-step">
    Start Your Server [#5-start-your-server-1]

    Go to the `Console` page and click **Restart**. Your bot should come online and connect to Discord.
  </div>
</div>

Installing Additional Packages [#installing-additional-packages-1]

If you need to add more pip packages later:

<div className="fd-steps">
  <div className="fd-step">
    Switch to Bash [#1-switch-to-bash]

    Set the **Startup Command** to `/bin/bash` and restart.
  </div>

  <div className="fd-step">
    Install the Package [#2-install-the-package]

    In the `Console`, run:

    ```
    pip3 install package-name
    ```
  </div>

  <div className="fd-step">
    Switch Back [#3-switch-back]

    Set the **Startup Command** back to `python3 bot.py` (or your main file) and restart.

    ***
  </div>
</div>

Troubleshooting [#troubleshooting]

* **Bot starts but immediately crashes** — Check the `Console` for error messages. Common issues include a missing or invalid bot token.
* **"ModuleNotFoundError" errors** — Dependencies are missing. On the Discord Bot server, set startup to `/bin/bash`, run `pip3 install -r requirements.txt`, then switch back. On the standalone Python server, check that your `requirements.txt` lists all required packages.
* **Server stuck on "Starting"** — The panel may not detect startup output. Join our [Discord](https://discord.xgamingserver.com) for help.
* **Wrong Python version** — Contact support to switch the Docker image. Available versions: Python 2.7, 3.7, 3.8, 3.9, 3.10.
* **"SyntaxError" on startup** — You may be running code written for a newer Python version than what is installed.
