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

# Discord

> Send messages and interact with Discord servers

## Overview

Discord tool allows you to send messages via webhooks or bot tokens to Discord servers.

The user asks to post or read messages; the agent calls Discord and returns the outcome.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "DiscordTool Flow"
        User[👤 User] --> Agent[🤖 Agent]
        Agent --> Tool[🔧 DiscordTool]
        Tool --> Result[✅ Result]
        Result --> Agent
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent agent
    class Tool tool
    class Result output
```

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonai[tools]"
```

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
export DISCORD_BOT_TOKEN=your_bot_token  # Optional
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_tools import DiscordTool

    # Initialize with webhook
    discord = DiscordTool(webhook_url="https://discord.com/api/webhooks/...")

    # Send message
    discord.send_webhook("Hello from PraisonAI!")
    ```
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see **Usage with Agent** below, or pass env vars and options from the sections above.
  </Step>
</Steps>

## Usage with Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonai_tools import DiscordTool

agent = Agent(
    name="DiscordBot",
    instructions="You send notifications to Discord.",
    tools=[DiscordTool()]
)

response = agent.chat("Send an alert to Discord about the new release")
print(response)
```

## Available Methods

### send\_webhook(content, username=None)

Send a message via webhook.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai_tools import DiscordTool

discord = DiscordTool()
discord.send_webhook("Alert: System is down!", username="AlertBot")
```

### send\_message(channel\_id, content)

Send a message to a channel (requires bot token).

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
discord.send_message("123456789", "Hello!")
```

## Common Errors

| Error                                | Cause             | Solution                 |
| ------------------------------------ | ----------------- | ------------------------ |
| `DISCORD_WEBHOOK_URL not configured` | Missing webhook   | Set environment variable |
| `Invalid webhook`                    | Wrong URL         | Check webhook URL        |
| `Rate limited`                       | Too many messages | Add delays               |

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Tool as Tool
    participant Svc as Discord API

    User->>Agent: Request
    Agent->>Tool: Call tool
    Tool->>Svc: Query
    Svc-->>Tool: Data
    Tool-->>Agent: Result
    Agent-->>User: Response
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Store the bot token securely">
    Read the Discord token from the environment, never hard-code it in the tool.
  </Accordion>

  <Accordion title="Scope bot permissions">
    Grant the bot only the channels and permissions it needs for the task.
  </Accordion>

  <Accordion title="Handle rate limits">
    Discord returns HTTP 429 under load. Retry with backoff so the agent stays responsive.
  </Accordion>
</AccordionGroup>

***

## Related Tools

<CardGroup cols={2}>
  <Card title="Slack" icon="book" href="/docs/tools/external/slack">
    Slack messaging
  </Card>

  <Card title="Telegram" icon="book" href="/docs/tools/external/telegram">
    Telegram bot
  </Card>

  <Card title="Email" icon="book" href="/docs/tools/external/email">
    Email notifications
  </Card>
</CardGroup>
