> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.daki.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a Python Bot

> Step-by-step guide to deploying a Python Discord bot (discord.py or py-cord) on Daki Hosting.

This guide walks you through deploying a Python Discord bot on Daki Hosting — from creating your server to reading your bot token securely and going live.

## What you'll learn

* How to create a Python server for your bot
* How to upload your code
* How to configure the install command, startup command, and Python version
* How to set your bot token securely using a `.env` file
* How to start your bot and verify it works

***

## Prerequisites

* A Daki account (Free Tier or paid) — see [Create an Account](./account-create)
* A Discord bot with a **bot token**, created in the [Discord Developer Portal](https://discord.com/developers/applications)
* Your bot's source code, including a `requirements.txt` listing all dependencies (e.g., `discord.py` or `py-cord`, and `python-dotenv`)

<Info>
  Discord bots connect **outbound** to Discord's servers and do not require an inbound port. This means Discord bots work on both Free Tier and paid plans. If your bot also runs an HTTP server (e.g., for webhooks or a web dashboard), you will need a paid plan, as publicly accessible ports are only available on paid plans. See [Network & Allocations](./network-allocations).
</Info>

***

## Deployment

<Steps>
  <Step title="Create a Python server">
    1. Log in to the <Tooltip tip="The free-hosting site (dash.daki.cc) where you manage your free server.">Free Tier Dashboard</Tooltip> at [dash.daki.cc](https://dash.daki.cc) or the <Tooltip tip="Daki's billing site (billing.daki.cc) for plans, invoices, credits, and payments.">Billing Panel</Tooltip> at [billing.daki.cc](https://billing.daki.cc).
    2. Create a new server and select the **Python** <Tooltip tip="A preconfigured template that sets your server's language and type.">egg</Tooltip>.
    3. Give your server a name (e.g., `MyPythonBot`).

    See [Create Your First Server](./create-server) for the full walkthrough.
  </Step>

  <Step title="Access the Portal">
    Log in to the <Tooltip tip="Daki's Pterodactyl-based server-management panel (portal.daki.cc).">Portal</Tooltip> via <Tooltip tip="Single sign-on — one-click Portal login with no separate password.">SSO</Tooltip> or directly at [portal.daki.cc](https://portal.daki.cc). See [Portal Overview](./portal).
  </Step>

  <Step title="Upload your bot's code">
    **Option A — Upload as a ZIP (simplest):**

    1. Compress your project folder into a `.zip` file.
    2. In the Portal, go to the **Files** tab and click **Upload**.
    3. Right-click the `.zip` and click **Extract**.

    **Option B — Use SFTP (no size limits):**
    Use your <Tooltip tip="Secure File Transfer Protocol — upload/download files with no size limits.">SFTP</Tooltip> credentials from the **Settings** tab to upload the folder directly. See [File Manager](./file-manager).

    <Info>
      Include a `requirements.txt` in your project root. This is used by the install command to install your dependencies.
    </Info>
  </Step>

  <Step title="Configure the Startup tab">
    Open the **Startup** tab and configure all three fields:

    **1. Docker Image** — Select the Python version your bot requires (e.g., **Python 3.12**). Choose the latest available version if unsure.

    **2. Install Command** — Set this to install your dependencies automatically:

    ```
    pip install -r requirements.txt
    ```

    **3. Startup Command** — Set this to the command that runs your bot:

    * `python main.py` — if your entry file is `main.py`
    * `python bot.py` — if your entry file is `bot.py`
    * `python -m mypackage` — if your project is structured as a package

    You are free to adjust these commands to match your project's structure and requirements.

    See [Startup Settings](./startup-settings) for a full explanation.
  </Step>

  <Step title="Add your bot token via a .env file">
    Store your Discord bot token in a `.env` file on the server so it never appears in your source code.

    1. In the **Files** tab, click **New File** and name it `.env`.
    2. Add your token:
       ```
       BOT_TOKEN=your_discord_bot_token_here
       ```
    3. Click **Save**.

    Make sure `python-dotenv` is in your `requirements.txt`, then load the file in your code:

    ```python theme={null}
    from dotenv import load_dotenv
    import os
    import discord

    load_dotenv()
    TOKEN = os.environ.get("BOT_TOKEN")

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

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

    client.run(TOKEN)
    ```

    See [Environment Variables](./environment-variables) for more details on using `.env` files.
  </Step>

  <Step title="Start your bot">
    Click **Start** in the **Console** tab. A successful launch will print:

    ```
    Logged in as MyBot#1234
    ```

    If you see errors, check the [Troubleshooting](./troubleshooting) guide.
  </Step>
</Steps>

***

## Common Issues

<AccordionGroup>
  <Accordion title="ModuleNotFoundError: No module named 'discord'">
    Your dependencies were not installed. Check that `discord.py` or `py-cord` is listed in `requirements.txt`, and that the install command is set to `pip install -r requirements.txt` in the Startup tab. Restart the server to trigger the install.
  </Accordion>

  <Accordion title="ModuleNotFoundError: No module named 'dotenv'">
    Add `python-dotenv` to your `requirements.txt` and restart the server.
  </Accordion>

  <Accordion title="discord.errors.LoginFailure: Improper token has been passed">
    Your token in the `.env` file is incorrect or missing. Open the `.env` file in the Files tab and check the value carefully. Remove any extra spaces or quotes.
  </Accordion>

  <Accordion title="PrivilegedIntentsRequired error">
    Your bot is requesting intents that are not enabled in the Discord Developer Portal. Enable the required privileged intents (e.g., Message Content Intent) in your bot application's settings, and make sure your code requests the same intents.
  </Accordion>

  <Accordion title="Server crashes immediately on start">
    Read the Console output for the error. Common causes: wrong startup command (filename typo or wrong path), missing `requirements.txt`, or a missing package. See [Troubleshooting](./troubleshooting).
  </Accordion>
</AccordionGroup>

***

## Next Steps

* [Environment Variables](./environment-variables) — Full guide on `.env` files and reading variables in code.
* [Keep Your Free Server Active](./save-free-server-from-purge) — Watch ads regularly to keep your Free Tier server running.
* [File Manager](./file-manager) — Update your code after making changes.
