Discord Bot Setup — OpenClaw Integration Guide
Complete guide to setting up Discord as a channel for OpenClaw. Covers bot creation, permissions, authorization errors, slash commands, duplicate messages, per-channel configuration, and credential storage.
⚠️ The Problem
🔍 Why This Happens
groupPolicy: "allowlist" blocks all guilds/channels not explicitly configured
4. Duplicate gateway instances: After updates, old gateway processes may run alongside new ones, causing duplicate messages
5. Bot invitation issues: Bot may lack proper scopes/permissions, or channel ID may be incorrect
6. Separate session contexts: Each Discord channel/thread is a separate session — credentials shared in one don't carry to others✅ The Fix
## Step 1: Create Your Discord Bot
1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Click New Application and name it
3. Go to Bot section → Click Add Bot
4. Copy the bot token (click Reset Token if needed)
Critical: Enable Privileged Intents:
- Scroll down to Privileged Gateway Intents
- Enable Message Content Intent ✅ (REQUIRED for reading messages)
- Enable Server Members Intent ✅ (recommended)
- Save changes
## Step 2: Generate Bot Invite URL
Go to OAuth2 → URL Generator:
- Scopes: Select bot and applications.commands
- Bot Permissions: Select at minimum:
- Send Messages
- Read Message History
- Use Slash Commands
- (Optional) Administrator for full access
- Copy the generated URL and open it to invite the bot to your server
## Step 3: Configure Discord in OpenClaw
// ~/.openclaw/config.json5{ channels: { discord: { enabled: true, botToken: "YOUR_DISCORD_BOT_TOKEN", dmPolicy: "pairing", // or "allowlist", "open" groupPolicy: "allowlist", // guilds must be explicitly allowed guilds: { "YOUR_GUILD_ID": { users: ["YOUR_USER_ID"], // authorized users channels: { "YOUR_CHANNEL_ID": { allow: true } } } } } }}How to get IDs:
1. Enable Developer Mode: Discord Settings → App Settings → Advanced → Developer Mode
2. Right-click server → Copy Server ID (Guild ID)
3. Right-click channel → Copy Channel ID
4. Right-click yourself → Copy User ID
## Step 4: Fix 'Not Authorized' Errors
The 'not authorized' message comes from OpenClaw, not Discord. Even with Discord admin permissions, you must be authorized in OpenClaw:
For DMs (using pairing):
# List pending Discord pairing requestsopenclaw pairing list discord# Approve your pairing codeopenclaw pairing approve discord <code>For Server Channels (using allowlist):
channels: { discord: { groupPolicy: "allowlist", guilds: { "123456789012345678": { // Your Guild ID users: ["987654321098765432"], // Your User ID channels: { "111222333444555666": { allow: true } // Channel ID } } } }}## Step 5: Fix 'Unknown Channel' Errors
If the bot receives messages but fails to reply with Unknown Channel:
1. Verify the channel ID is correct — Right-click channel → Copy ID
2. Check bot permissions in that channel — Bot needs Send Messages permission
3. Ensure the channel exists — Private channels or deleted channels cause this
4. Try recreating the bot — Sometimes the bot-channel binding gets corrupted
# Check what channels the bot can seeopenclaw logs --follow | grep -i channel## Step 6: Fix Duplicate Messages
If you're seeing every message processed twice:
# Check for duplicate gateway instancesopenclaw status --deep# Look under 'Health' → 'Discord' → 'Agents active'# Should show only ONE agent, not duplicates# Also check for old processesps aux | grep -E '(clawdbot|moltbot|openclaw).*gateway'# Kill any old instancesclawdbot gateway stop 2>/dev/nullmoltbot gateway stop 2>/dev/null# Restart OpenClaw onlyopenclaw gateway restartAfter migration (Clawdbot/Moltbot → OpenClaw):
# Stop ALL gateway servicessudo systemctl stop clawdbot-gateway 2>/dev/nullsudo systemctl stop moltbot-gateway 2>/dev/nullsudo systemctl disable clawdbot-gateway 2>/dev/nullsudo systemctl disable moltbot-gateway 2>/dev/null# Keep only openclaw-gatewayopenclaw gateway restart## Step 7: Set Up Per-Channel System Prompts
Configure different prompts for different channels:
channels: { discord: { guilds: { "YOUR_GUILD_ID": { channels: { "support-channel": { allow: true, systemPrompt: "You are a helpful support agent. Be concise and professional." }, "creative-channel": { allow: true, systemPrompt: "You are a creative writing assistant. Be imaginative and expressive." } } } } }}Note: Channel keys can be the channel ID (preferred) or slug (lowercase, spaces as dashes).
## Step 8: Store Credentials for Reuse
Each Discord channel/thread is a separate session. Credentials typed in chat won't carry over.
For API tokens (GitHub, etc.) — Store on the gateway host:
# Add to ~/.openclaw/.envecho 'GH_TOKEN=ghp_xxxxxxxxxxxx' >> ~/.openclaw/.envecho 'GITHUB_TOKEN=ghp_xxxxxxxxxxxx' >> ~/.openclaw/.env# Restart gateway to pick up env varsopenclaw gateway restartFor model credentials — Configure in config.json5, not in chat:
models: { providers: { anthropic: { apiKey: "sk-ant-xxxxx" }, openai: { apiKey: "sk-xxxxx" } }}## Step 9: Verify Everything is Working
# Full status checkopenclaw status --deep# Check Discord specificallyopenclaw channels status# Should show:# - Discord: enabled, configured, running# Test the connection# Send a message in your allowed channel: @YourBot hello# Watch logs for issuesopenclaw logs --follow## Common Error Messages and Fixes
| Error | Cause | Fix |
|-------|-------|-----|
| The application did not respond | Gateway not running or bot misconfigured | Run openclaw gateway status, check logs |
| You are not authorized | User not in OpenClaw allowlist | Add user ID to guilds.users array |
| Unknown Channel | Channel ID wrong or bot lacks permissions | Verify channel ID, check bot permissions |
| Missing Access | Bot not in server or lacks permissions | Re-invite bot with proper scopes |
| Duplicate messages | Multiple gateway instances running | Stop old instances, keep only openclaw-gateway |
🔥 Your AI should run your business, not just answer questions.
We'll show you how.$97/mo (going to $197 soon)
📋 Quick Commands
| Command | Description |
|---|---|
| openclaw pairing list discord | List pending Discord DM pairing requests |
| openclaw pairing approve discord <code> | Approve a Discord pairing request |
| openclaw channels status | Check status of Discord channel connection |
| openclaw status --deep | Full status check including agent count (detects duplicates) |
| openclaw gateway restart | Restart gateway to apply configuration changes |
| openclaw logs --follow | Watch live logs for Discord-related errors |
Related Issues
📚 You Might Also Like
Discord
Add your AI assistant to Discord servers and DMs. Full bot support with slash commands, rich embeds, threads, and role-based access control. Perfect for teams, communities, and developers.
How to Run AI Locally: Complete Step-by-Step Guide
Want to run AI on your own computer — no cloud, no subscriptions, no data leaving your machine? This tutorial walks you through everything from Ollama to full assistant setup.
How to Connect Gmail to Your AI Assistant (Complete Integration Guide)
Turn Gmail into an AI-powered inbox. Summarize threads, draft replies, auto-categorize messages, and search your email with natural language.
OpenClaw vs ChatGPT
Why a personal assistant beats a chatbot
🐙 Your AI should run your business.
Weekly live builds + template vault. We'll show you how to make AI actually work.$97/mo (going to $197 soon)
Join Vibe Combinator →