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

# How to Host Discord Bots

> Learn how to create and host Discord bots on Shard Cloud with Node.js and Python examples.

## Introduction

This guide covers creating and deploying Discord bots on Shard Cloud with examples in both Node.js and Python.

## Creating a Discord Bot Application

<Steps>
  <Step title="Create Application">
    Go to the [Discord Developer Portal](https://discord.com/developers/applications) and click **"New Application"**. Give your bot a name and create it.
  </Step>

  <Step title="Get Bot Token">
    Navigate to the **"Bot"** tab and click **"Reset Token"** to generate your bot token. **Copy and save it securely**.
  </Step>

  <Step title="Enable Intents">
    In the **"Bot"** tab, scroll to **"Privileged Gateway Intents"** and enable:

    * Presence Intent
    * Server Members Intent
    * Message Content Intent
  </Step>
</Steps>

<Warning>
  **Security**: Never share your bot token publicly. It grants full control over your bot.
</Warning>

## Creating Your Bot

<Tabs>
  <Tab title="Discord.js (Node.js)">
    ### Setup

    ```bash theme={null}
    npm init -y
    npm install discord.js
    ```

    ### Basic Bot Code

    ```javascript index.js theme={null}
    const { Client, GatewayIntentBits } = require('discord.js');

    const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
      ],
    });

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

    client.on('messageCreate', (message) => {
      if (message.content === '!ping') {
        message.reply('Pong!');
      }
    });

    client.login('YOUR_BOT_TOKEN');
    ```

    ### Package.json

    ```json package.json theme={null}
    {
      "name": "discord-bot",
      "version": "1.0.0",
      "main": "index.js",
      "dependencies": {
        "discord.js": "^14.0.0"
      }
    }
    ```

    ### Shard Cloud Configuration

    ```systemd .shardcloud theme={null}
    DISPLAY_NAME=Discord Bot
    DESCRIPTION=My Discord Bot
    MAIN=index.js
    MEMORY=512
    VERSION=recommended
    ```
  </Tab>

  <Tab title="Discord.py (Python)">
    ### Setup

    ```bash theme={null}
    pip install discord.py
    ```

    ### Basic Bot Code

    ```python main.py theme={null}
    import discord
    from discord.ext import commands

    intents = discord.Intents.default()
    intents.message_content = True

    bot = commands.Bot(command_prefix='!', intents=intents)

    @bot.event
    async def on_ready():
        print(f'{bot.user} is now running!')

    @bot.command()
    async def ping(ctx):
        await ctx.reply('Pong!')

    bot.run('YOUR_BOT_TOKEN')
    ```

    ### Requirements.txt

    ```txt requirements.txt theme={null}
    discord.py
    ```

    ### Shard Cloud Configuration

    ```systemd .shardcloud theme={null}
    DISPLAY_NAME=Discord Bot
    DESCRIPTION=My Discord Bot
    MAIN=main.py
    MEMORY=512
    VERSION=recommended
    ```
  </Tab>
</Tabs>

## Inviting Your Bot

1. Go to the [Developer Portal](https://discord.com/developers/applications)
2. Select your bot → **OAuth2** → **URL Generator**
3. Check **"bot"** scope
4. Select required permissions
5. Copy and open the generated URL to invite your bot

## Deploying

<Steps>
  <Step title="Prepare Your Files">
    Ensure you have:

    * Your bot code file
    * `package.json` (Node.js) or `requirements.txt` (Python)
    * `.shardcloud`
  </Step>

  <Step title="Exclude Unnecessary Files">
    Remove: `node_modules/`, `__pycache__/`, `venv/`
  </Step>

  <Step title="Create ZIP Archive">
    Compress your project folder.
  </Step>

  <Step title="Upload to Shard Cloud">
    Go to [Shard Cloud Dashboard](https://shardcloud.app/dash/applications) and upload.
  </Step>
</Steps>

## Testing

After deployment, test your bot by sending `!ping` in a server where your bot is present. It should reply with "Pong!".

## Additional Resources

* [Discord.js Guide](https://discordjs.guide/)
* [Discord.py Documentation](https://discordpy.readthedocs.io/)

## Troubleshooting

<AccordionGroup>
  <Accordion title="Bot not responding">
    * Verify your bot token is correct
    * Check that intents are enabled in Developer Portal
    * Review logs in the Shard Cloud dashboard
  </Accordion>

  <Accordion title="Missing permissions">
    Re-invite your bot with the necessary permissions enabled.
  </Accordion>
</AccordionGroup>
