> ## 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 Discord.js Bot

> Step-by-step guide to deploying a Discord.js (Node.js) bot on Daki Hosting.

This guide walks you through deploying a Discord.js bot on Daki Hosting — from creating your server to having your bot online and reading its token securely.

## What you'll learn

* How to create a Node.js server for your bot
* How to upload your code
* How to configure the install command, startup command, and <Tooltip tip="The specific runtime version your server's container runs (e.g. Node.js 22).">Docker image</Tooltip>
* 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 `package.json` with `discord.js` and `dotenv` as dependencies

<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 serves HTTP requests (e.g., for slash command interactions or webhooks), 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 Node.js 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 **Node.js** <Tooltip tip="A preconfigured template that sets your server's language and type.">egg</Tooltip>.
    3. Give your server a name (e.g., `MyDiscordBot`).

    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> (from the Credentials tab or your Billing Panel service page), 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 locally.
    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):**
    Connect using your <Tooltip tip="Secure File Transfer Protocol — upload/download files with no size limits.">SFTP</Tooltip> credentials from the **Settings** tab and upload your folder directly. See [File Manager](./file-manager).

    <Info>
      Do **not** include your `node_modules` folder in the upload — it will be installed automatically by the install command. Do include your `package.json` and `package-lock.json`.
    </Info>
  </Step>

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

    **1. Docker Image** — Select the Node.js version your bot requires (e.g., **Node.js 20** or **Node.js 22**). Node.js 20 LTS is a safe default if unsure.

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

    ```
    npm install
    ```

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

    * `node index.js` — if your entry file is `index.js`
    * `node bot.js` — if your entry file is `bot.js`
    * `npm start` — if you have a `start` script in `package.json`

    You are free to adjust these commands to match your project structure.

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

  <Step title="Add your bot token via a .env file">
    Your bot needs its Discord token to connect. Store it in a `.env` file on the server so it never ends up 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**.

    In your bot code, load it with `dotenv`:

    ```js theme={null}
    require('dotenv').config();

    const { Client, GatewayIntentBits } = require('discord.js');
    const client = new Client({ intents: [GatewayIntentBits.Guilds] });

    client.once('ready', () => {
        console.log(`Logged in as ${client.user.tag}`);
    });

    client.login(process.env.BOT_TOKEN);
    ```

    Make sure `dotenv` is listed in your `package.json` dependencies so it gets installed by the install command.

    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 your bot's login confirmation:

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

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

***

## Common Issues

<AccordionGroup>
  <Accordion title="Error: Cannot find module 'discord.js'">
    Your dependencies were not installed. Check that your `package.json` lists `discord.js` as a dependency, and that the install command is set to `npm install` in the Startup tab. Restart the server to trigger the install.
  </Accordion>

  <Accordion title="Error: Cannot find module 'dotenv'">
    Add `dotenv` to your `package.json` dependencies and restart the server to reinstall.
  </Accordion>

  <Accordion title="Error: An invalid token was provided">
    Your bot token in the `.env` file is incorrect or missing. Go to the Files tab, open `.env`, and verify the value. Make sure there are no extra spaces, quotes, or line breaks.
  </Accordion>

  <Accordion title="Bot starts but disconnects shortly after">
    This is usually caused by missing Gateway Intents. In the Discord Developer Portal, enable the required privileged intents (e.g., Message Content Intent) for your bot application, and ensure your code requests them.
  </Accordion>

  <Accordion title="Server crashes immediately on start">
    Open the Console tab and read the error. Common causes: wrong startup command (filename typo), wrong Node.js version, or missing `node_modules`. 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 to keep your Free Tier server alive.
* [File Manager](./file-manager) — Update your code files after making changes.
