Discord Integration
Bring your knowledge base into Discord communities with an AI-powered bot, slash commands, and server history sync.
Features
| Feature | Description |
|---|---|
| Server Sync | Index channel messages, threads, and forums |
| Slash Commands | \/ask\, \/search\, \/summarize\ |
| @Mentions | Respond when mentioned in channels |
| Thread Support | Full thread conversation context |
| Embeds | Rich responses with citations and buttons |
| Role-Based Access | Respect Discord server permissions |
| Webhook Notifications | Document update alerts to channels |
Prerequisites
- Discord account with Manage Server permissions
- Discord Developer Portal access
- LH42 organization with Discord integration enabled
Setup
Step 1: Create Discord Application
- Go to Discord Developer Portal
- Click New Application
- Name it (e.g., "LH42 Assistant")
- Note the Application ID and Public Key from General Information
Step 2: Create Bot User
- Go to Bot section in your application
- Click Add Bot
- Configure bot settings:
- Disable Public Bot (unless you want anyone to add it)
- Enable Message Content Intent (required for reading messages)
- Enable Server Members Intent (for user resolution)
- Click Reset Token and copy the Bot Token
Step 3: Configure OAuth2 & Permissions
- Go to OAuth2 > URL Generator
- Select scopes:
- \bot\
- \applications.commands\
- Select bot permissions:
- Read Messages/View Channels
- Send Messages
- Send Messages in Threads
- Embed Links
- Attach Files
- Read Message History
- Add Reactions
- Use Slash Commands
- Copy the generated URL
Step 4: Invite Bot to Server
- Open the OAuth2 URL in your browser
- Select your Discord server
- Authorize the permissions
- Bot appears in your server
Step 5: Configure in LH42
- Go to Settings > Integrations > Discord
- Enter your Discord credentials:
\\\`python
client.integrations.discord.configure({
"application_id": "your-application-id",
"public_key": "your-public-key",
"bot_token": "your-bot-token", # Encrypted at rest
"guild_ids": ["your-server-id"] # Optional: limit to specific servers
})
\\\`
Step 6: Register Slash Commands
\\\`bash
# Commands are auto-registered, or manually:
POST /api/integrations/discord/commands/register
\\\`
Using the Bot
Slash Commands
\\\`
/ask query:What is our refund policy?
/search query:quarterly report 2024
/summarize url:https://docs.example.com/guide
\\\`
Response includes:
- AI-generated answer
- Source citations with links
- Feedback buttons (👍/👎)
@Mentions
\\\`
@LH42 Can you explain our deployment process?
\\\`
Thread Conversations
The bot maintains context in threads:
\\\`
User: @LH42 What's our vacation policy?
LH42: Based on the Employee Handbook, you get 20 days PTO...
User: Does that include sick days?
LH42: No, sick days are separate. You have unlimited sick days...
\\\`
Data Ingestion
What Gets Indexed
| Content | Indexed | Notes |
|---|---|---|
| Text channel messages | ✅ | Full text searchable |
| Thread messages | ✅ | With parent context |
| Forum posts | ✅ | Title + content |
| Attachments | ✅ | PDFs, images (OCR) |
| Embeds | ✅ | Title + description |
| Reactions | ✅ | As engagement metadata |
| DMs | ❌ | Privacy - never indexed |
Sync Configuration
\\\`python
client.connectors.configure("discord", {
"settings": {
"guild_ids": ["123456789"], # Server IDs to sync
"channel_ids": ["456789123"], # Optional: specific channels
"include_threads": True,
"include_forums": True,
"include_files": True,
"lookback_days": 90,
"sync_schedule": "0 */4 * * *" # Every 4 hours
}
})
\\\`
Embed Responses
Responses use Discord embeds for rich formatting:
\\\`json
{
"embeds": [{
"title": "Here's what I found",
"description": "Based on the Employee Handbook...",
"color": 5814783,
"fields": [
{
"name": "📄 Sources",
"value": "Employee Handbook • PTO Policy"
}
],
"footer": {
"text": "Powered by LH42"
}
}],
"components": [{
"type": 1,
"components": [
{"type": 2, "style": 2, "label": "👍 Helpful", "custom_id": "feedback_positive"},
{"type": 2, "style": 2, "label": "👎 Not helpful", "custom_id": "feedback_negative"}
]
}]
}
\\\`
Webhook Architecture
Discord uses the Interactions Endpoint:
\\\`
Discord Interaction → POST /api/gateway/discord/events
│
├── Verify Ed25519 signature
│
├── PING (type=1) → Return PONG
│
├── APPLICATION_COMMAND (type=2)
│ ├── Parse slash command
│ ├── Queue to Inngest
│ └── Return DEFERRED response
│
└── MESSAGE_COMPONENT (type=3)
└── Handle button clicks (feedback)
\\\`
Bot Configuration
\\\`python
client.integrations.discord.configure({
"bot": {
"name": "LH42 Assistant",
"response_style": "concise", # concise | detailed
"embed_color": 5814783, # Brand color
"show_citations": True,
"show_feedback_buttons": True,
"typing_indicator": True,
"error_dm": False
},
"channels": {
"mentionsOnly": True, # Only respond to @mentions
"allowed_channel_ids": [], # Empty = all channels
"excluded_channel_ids": [] # Blacklist channels
}
})
\\\`
Notifications
Set up automated notifications:
\\\`python
client.integrations.discord.create_notification({
"name": "New Document Alert",
"channel_id": "123456789",
"events": ["document.processed"],
"template": {
"embeds": [{
"title": "📄 New document indexed",
"description": "{title}\n{summary}",
"color": 3066993
}]
}
})
\\\`
Security
| Aspect | Implementation |
|---|---|
| Signature | Ed25519 verification |
| Tokens | Encrypted at rest |
| Scopes | Minimal bot permissions |
| Audit | All interactions logged |
Troubleshooting
| Issue | Solution |
|---|---|
| Bot not responding | Verify bot is in server with correct permissions |
| "Invalid signature" | Check Public Key matches in LH42 config |
| Commands not showing | Re-register commands, may take up to 1 hour |
| Missing messages | Enable Message Content Intent in Developer Portal |
API Reference
List Servers
\\\`bash
GET /api/integrations/discord/guilds
# Response
{
"guilds": [
{
"id": "123456789",
"name": "My Server",
"member_count": 150,
"channels_synced": 10
}
]
}
\\\`
Send Message
\\\`bash
POST /api/integrations/discord/send
{
"channel_id": "123456789",
"content": "Hello from LH42!",
"embed": {...}
}
\\\`
Next Steps
- Slack Integration - Similar setup for Slack
- Communication Overview - Architecture deep-dive