# Discord Bot Integration

Connect your LVNG workspace to Discord to sync channels, enable AI-powered responses, and let your digital twins participate in Discord conversations.

## Prerequisites

- An LVNG account with an API key
- A Discord application with a bot token ([Discord Developer Portal](https://discord.com/developers/applications))
- The bot added to your Discord server with `Send Messages`, `Read Message History`, and `View Channels` permissions

## Step 1: Create Integration

Register your Discord bot as a platform integration in LVNG.

```bash
curl -X POST https://api.lvng.ai/api/v2/platform-integrations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "discord",
    "name": "My Discord Bot",
    "workspace_id": "YOUR_WORKSPACE_ID",
    "config": {
      "bot_token": "YOUR_DISCORD_BOT_TOKEN",
      "guild_id": "YOUR_GUILD_ID"
    }
  }'
```

## Step 2: Sync Channels

Import your Discord channels into LVNG. This creates matching LVNG channels linked to your Discord channels.

```bash
curl -X POST https://api.lvng.ai/api/v2/platform-integrations/INTEGRATION_ID/sync-channels \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Step 3: Test Connection

Verify the integration is working correctly.

```bash
curl -X POST https://api.lvng.ai/api/v2/platform-integrations/INTEGRATION_ID/test \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Webhook Setup (Optional)

For Discord Interactions (slash commands, buttons), set the interactions endpoint URL in your Discord application settings.

```bash
# Discord Interaction Endpoint URL:
# https://api.lvng.ai/webhooks/discord
#
# Set this in your Discord application settings under
# "Interactions Endpoint URL"
#
# The server verifies requests using Ed25519 signatures
# with your application's public key.
```

> **Important:** Discord does not support markdown tables in messages. LVNG automatically converts table-formatted responses to bullet lists for Discord.

## How It Works

Once connected, the integration works as follows:

1. Messages sent in synced Discord channels are received by the LVNG bot adapter
2. LVNG processes the message through the AI routing system
3. AI responses are streamed back to the Discord channel via the bot
4. Digital twins assigned to the channel can also participate in conversations

## Next Steps

- [Platform Integrations API](/docs/api/integrations) -- Full endpoint reference
- [Digital Twins API](/docs/api/twins) -- Add AI personas to your channels
- [Agents API](/docs/api/agents) -- Deploy autonomous agents
