# 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](https://daki.cc/wiki/guides/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](https://daki.cc/wiki/guides/network-allocations).

---

## Deployment

**Step 1: Create a Python server**

1. Log in to the Free Tier Dashboard at [dash.daki.cc](https://dash.daki.cc) or the Billing Panel at [billing.daki.cc](https://billing.daki.cc).
2. Create a new server and select the **Python** egg.
3. Give your server a name (e.g., `MyPythonBot`).

See [Create Your First Server](https://daki.cc/wiki/guides/create-server) for the full walkthrough.

**Step 2: Access the Portal**

Log in to the Portal via SSO or directly at [portal.daki.cc](https://portal.daki.cc). See [Portal Overview](https://daki.cc/wiki/guides/portal).

**Step 3: 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 SFTP credentials from the **Settings** tab to upload the folder directly. See [File Manager](https://daki.cc/wiki/guides/file-manager).

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

**Step 4: 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](https://daki.cc/wiki/guides/startup-settings) for a full explanation.

**Step 5: 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

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](https://daki.cc/wiki/guides/environment-variables) for more details on using `.env` files.

**Step 6: 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](https://daki.cc/wiki/guides/troubleshooting) guide.

---

## Common Issues

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

**ModuleNotFoundError: No module named 'dotenv'**

Add `python-dotenv` to your `requirements.txt` and restart the server.

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

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

**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](https://daki.cc/wiki/guides/troubleshooting).

---

## Next Steps

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

---
Source: https://daki.cc/wiki/guides/deploy-python
