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

# Discord Bot

> Deploy an agent as a Discord bot with tools and memory.

Build a Discord bot with tools and persistent memory.

<Steps>
  <Step title="Create the bot">
    1. Go to the [Discord Developer Portal](https://discord.com/developers/applications)
    2. Click **New Application** and name it
    3. Go to **Bot** and click **Add Bot**
    4. Enable **MESSAGE\_CONTENT** under Privileged Gateway Intents
    5. Copy the bot token
    6. Use the OAuth2 URL Generator to invite the bot (select `bot` scope with `Send Messages` and `Read Message History`)
  </Step>

  <Step title="Create the agent">
    ```python discord_bot.py theme={null}
    import asyncio
    import os
    from definable.agent import Agent
    from definable.agent.interface import DiscordInterface
    from definable.memory import Memory, SQLiteStore
    from definable.tool.decorator import tool

    @tool
    def search_docs(query: str) -> str:
        """Search documentation for an answer."""
        return f"Found results for: {query}"

    agent = Agent(
        model="gpt-4o",
        instructions="You are a helpful Discord bot.",
        tools=[search_docs],
        memory=Memory(store=SQLiteStore("./discord_memory.db")),
    )

    discord = DiscordInterface(
        agent=agent,
        bot_token=os.environ["DISCORD_BOT_TOKEN"],
    )

    asyncio.run(discord.serve_forever())
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash theme={null}
    pip install 'definable[discord]'
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export DISCORD_BOT_TOKEN="your-bot-token"
    export OPENAI_API_KEY="sk-..."
    ```
  </Step>

  <Step title="Run">
    ```bash theme={null}
    python discord_bot.py
    ```

    Mention the bot or send a DM to start chatting.
  </Step>
</Steps>

See [Discord reference](/interfaces/discord) for all configuration options.
