OpenClaw + Discord Integration: Complete Setup Guide
Discord is one of the most requested channels for OpenClaw agents. Whether you run a developer community, a gaming server, or a private team workspace, having an AI agent available in Discord changes how your server operates. This guide covers everything from creating the bot to handling connection drops, rate limits, and multi-server deployments.
Creating a Discord Bot for OpenClaw
Before OpenClaw can connect to Discord, you need a Discord application with a bot user. This bot acts as the bridge between your OpenClaw agent and Discord's messaging system. The entire process takes about five minutes.
Step 1: Create a Discord Application
Go to the Discord Developer Portal. Click "New Application" in the top right. Give it a name that matches your agent — for example, "Orion-PM" or "Radar-SEO." This name appears in your application list but is not the bot's display name in Discord.
Step 2: Add a Bot User
In the left sidebar, click "Bot." Then click "Add Bot" and confirm. You can set a custom username and avatar here — this is what server members see when the bot sends messages. Under the bot settings, find the "Token" section and click "Reset Token" to generate a new one. Copy this token immediately — you will not be able to see it again.
Important: Never share your bot token publicly. If it is exposed in a commit, paste, or screenshot, regenerate it immediately in the Developer Portal.
Step 3: Store the Token in OpenClaw
Run the following command to save your Discord bot token in OpenClaw's configuration:
# Save your Discord bot token
openclaw config set channels.discord.bottoken YOUR_DISCORD_BOT_TOKEN
# Verify it was saved
openclaw config get channels.discord.bottokenOpenClaw stores this token in your local project configuration file. It is never sent to any external service other than Discord's own API.
Bot Permissions and Gateway Intents
Discord requires bots to declare which permissions they need and which "intents" they subscribe to. Intents control what events your bot receives from Discord's Gateway WebSocket. Getting these wrong is the most common reason a newly created bot does not respond to messages.
Enable Privileged Gateway Intents
In the Discord Developer Portal, navigate to your application > Bot. Scroll down to "Privileged Gateway Intents" and enable the following:
| Intent | Required? | Why |
|---|---|---|
| Message Content | Yes | Read the actual text of messages so the agent can respond |
| Server Members | Optional | Only needed if the agent references user roles or names |
| Presence | No | Not needed for standard agent functionality |
Critical: Without the Message Content intent enabled, your bot receives message events but the message content is empty. The agent will see that someone sent a message but cannot read what it says. This is the single most common "my bot is not responding" issue.
Generate the OAuth2 Invite URL
Go to OAuth2 > URL Generator. Select the bot scope. Then select the bot permissions your agent needs:
# Recommended bot permissions for an OpenClaw agent:
Send Messages # Reply to users
Read Message History # Access conversation context
View Channels # See which channels exist
Embed Links # Format responses with rich embeds
Attach Files # Send files (reports, charts)
Add Reactions # React to messages for acknowledgment
Use Slash Commands # If registering slash commands later
# Permission integer: 277025770560
# Full invite URL format:
https://discord.com/api/oauth2/authorize?client_id=YOUR_APP_ID&permissions=277025770560&scope=botCopy the generated URL from the bottom of the page and open it in your browser. Select the server you want to add the bot to and authorize it. The bot will appear in the server's member list as offline until you start the OpenClaw gateway.
OpenClaw Discord Channel Configuration
With the bot created and added to your server, configure OpenClaw to connect to it. The configuration controls how the agent interacts with Discord — which channels it listens to, whether it responds to all messages or only mentions, and how it formats responses.
# Required: Bot token from the Developer Portal
openclaw config set channels.discord.bottoken YOUR_TOKEN
# Optional: Respond only when @mentioned (recommended for busy servers)
openclaw config set channels.discord.mentionOnly true
# Optional: Restrict the bot to specific channel IDs
openclaw config set channels.discord.allowedChannels '["123456789012345678", "987654321098765432"]'
# Optional: Set a custom status message
openclaw config set channels.discord.status "Ready to help"
# Optional: Use embeds for formatted responses
openclaw config set channels.discord.useEmbeds true
# Start or restart the gateway to apply changes
openclaw gateway restartAfter restarting, check the gateway logs for a confirmation line:
# Check gateway logs for Discord connection
openclaw gateway logs | grep discord
# Expected output:
# [channel:discord] connected as BotName#1234
# [channel:discord] listening in 3 servers, 12 channelsIf you see [channel:discord] connected in the logs, your agent is live on Discord. Send a message in one of the allowed channels (or mention the bot if mentionOnly is enabled) to test it.
Common Issues: Connection Drops, Lotus Errors, and Rate Limits
Discord's WebSocket Gateway is reliable, but several conditions cause bots to disconnect or behave unexpectedly. Here are the most common problems and their fixes.
Connection Drops
The bot connects successfully but goes offline after a few hours. This happens when the host machine sleeps, the process runs out of memory, or Discord issues a reconnect request that the bot fails to handle.
# On Mac: prevent sleep from killing the gateway
caffeinate -i openclaw gateway start
# On Linux: check for OOM kills
dmesg | grep -i "oom|killed" | tail -10
# Enable auto-reconnect in OpenClaw config
openclaw config set channels.discord.autoReconnect true
openclaw config set channels.discord.reconnectDelay 5000
openclaw gateway restartThe "Lotus" Error
The Lotus error shows up as Error [Lotus]: Cannot connect to Discord Gateway in the logs. It means OpenClaw's Discord adapter failed to authenticate with Discord's WebSocket endpoint. The cause is almost always an invalid or expired bot token.
# Step 1: Verify the current token
openclaw config get channels.discord.bottoken
# Step 2: Go to Discord Developer Portal > Bot > Reset Token
# Copy the new token
# Step 3: Update the token in OpenClaw
openclaw config set channels.discord.bottoken NEW_TOKEN
# Step 4: Restart the gateway
openclaw gateway restart
# Step 5: Verify connection
openclaw gateway logs | grep "discord.*connected"The Lotus error also appears if the bot has been removed from all servers. Discord invalidates sessions for bots that have no server memberships. Re-invite the bot to at least one server before restarting.
Rate Limits
Discord enforces strict rate limits on bot API calls. If your agent sends too many messages too quickly, Discord returns a 429 status code and the bot is temporarily blocked. OpenClaw respects these limits automatically, but high-traffic scenarios can still trigger them.
# Check rate limit warnings in the logs
openclaw gateway logs | grep "rate.limit|429"
# Add a response delay to slow down the bot (milliseconds)
openclaw config set channels.discord.responseDelay 1000
# Limit concurrent conversations per server
openclaw config set channels.discord.maxConcurrent 3
# For high-traffic servers, consider running multiple bots
# with different agents handling different channelsReconnection Strategies
A production Discord bot needs to handle disconnections gracefully. Discord's Gateway sends reconnect requests during deployments, and network interruptions happen on any host. OpenClaw includes built-in reconnection logic, but you can tune it for your setup.
# Enable automatic reconnection (enabled by default)
openclaw config set channels.discord.autoReconnect true
# Delay before first reconnect attempt (milliseconds)
openclaw config set channels.discord.reconnectDelay 5000
# Maximum reconnect attempts before giving up
openclaw config set channels.discord.maxReconnectAttempts 10
# Exponential backoff multiplier (each retry waits longer)
openclaw config set channels.discord.backoffMultiplier 1.5
# Resume missed events after reconnection
openclaw config set channels.discord.resumeEvents trueWith these settings, OpenClaw will try to reconnect up to 10 times after a disconnection. The first attempt happens after 5 seconds, the second after 7.5 seconds, the third after 11.25 seconds, and so on. If all attempts fail, the gateway logs an error and stops trying. You can set up an external process monitor like pm2 or systemd to restart the entire gateway if this happens.
# Install pm2 globally
npm install -g pm2
# Start the OpenClaw gateway with pm2
pm2 start "openclaw gateway start" --name openclaw-discord
# Configure pm2 to restart on crash
pm2 set openclaw-discord:restart_delay 10000
pm2 set openclaw-discord:max_restarts 50
# Save the pm2 process list so it survives reboots
pm2 save
pm2 startupMulti-Server Setup
A single OpenClaw bot can serve multiple Discord servers simultaneously. When you invite the bot to a new server using the same OAuth2 URL, it automatically starts listening in that server's channels. No additional configuration is needed on the OpenClaw side.
# Allow the bot in all servers but restrict to specific channels
openclaw config set channels.discord.allowedChannels '[
"111111111111111111",
"222222222222222222",
"333333333333333333"
]'
# Or use server-specific configurations (advanced)
# Create a discord-servers.json in your agent directory:
{
"servers": {
"SERVER_ID_1": {
"allowedChannels": ["111111111111111111"],
"mentionOnly": false
},
"SERVER_ID_2": {
"allowedChannels": ["222222222222222222", "333333333333333333"],
"mentionOnly": true
}
}
}
# Reference it in config
openclaw config set channels.discord.serverConfig "./discord-servers.json"For teams that need different agent behaviors per server, the recommended approach is to run separate OpenClaw agents. Each agent gets its own bot token, its own SOUL.md, and connects to Discord independently. This keeps configurations clean and avoids complex routing logic.
# Agent 1: Community support bot for public server
cd ~/agents/support-bot
openclaw config set channels.discord.bottoken SUPPORT_BOT_TOKEN
openclaw gateway start --port 18790
# Agent 2: Internal team assistant for private server
cd ~/agents/team-assistant
openclaw config set channels.discord.bottoken TEAM_BOT_TOKEN
openclaw gateway start --port 18791
# Both agents run simultaneously on different portsMonitoring Bot Health
A Discord bot that silently goes offline is worse than no bot at all. Users will send messages expecting a response and get nothing. Set up monitoring so you know immediately when something breaks.
#!/bin/bash
# discord-health-check.sh
# Run this on a cron schedule: */5 * * * * /path/to/discord-health-check.sh
GATEWAY_STATUS=$(openclaw gateway status 2>&1)
DISCORD_STATUS=$(openclaw gateway logs --lines 20 | grep -c "discord.*connected")
if echo "$GATEWAY_STATUS" | grep -q "stopped"; then
echo "Gateway is down, restarting..."
openclaw gateway start
# Optional: send alert to Telegram
curl -s "https://api.telegram.org/botYOUR_TG_TOKEN/sendMessage" \
-d "chat_id=YOUR_CHAT_ID" \
-d "text=OpenClaw Discord bot restarted (gateway was stopped)"
fi
if [ "$DISCORD_STATUS" -eq 0 ]; then
echo "Discord channel not connected, restarting gateway..."
openclaw gateway restart
curl -s "https://api.telegram.org/botYOUR_TG_TOKEN/sendMessage" \
-d "chat_id=YOUR_CHAT_ID" \
-d "text=OpenClaw Discord bot reconnected (channel was disconnected)"
fiFor a more robust setup, use pm2's built-in monitoring or pair it with a status page service. The key metrics to watch are: gateway uptime, Discord WebSocket connection status, average response latency, and error rate in the logs.
# Monitor with pm2
pm2 monit
# Check specific metrics
pm2 show openclaw-discord
# View real-time logs
pm2 logs openclaw-discord --lines 50
# Set up pm2 alerts (requires pm2-logrotate module)
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 7Complete Setup Checklist
Use this checklist to verify your OpenClaw Discord integration is fully configured. Each step builds on the previous one.
# 1. Create Discord application and bot
# discord.com/developers/applications > New Application > Bot > Add Bot
# 2. Enable Message Content Intent
# Bot settings > Privileged Gateway Intents > Message Content Intent: ON
# 3. Generate invite URL and add bot to server
# OAuth2 > URL Generator > scope: bot > permissions: 277025770560
# 4. Configure OpenClaw with bot token
openclaw config set channels.discord.bottoken YOUR_TOKEN
# 5. Set optional preferences
openclaw config set channels.discord.mentionOnly true
openclaw config set channels.discord.useEmbeds true
# 6. Start or restart the gateway
openclaw gateway restart
# 7. Verify connection
openclaw gateway logs | grep "discord.*connected"
# 8. Test by sending a message in Discord
# @YourBot hello, are you working?
# 9. Set up monitoring (optional but recommended)
# crontab -e > add health check script every 5 minutes
# 10. Configure pm2 for production uptime
pm2 start "openclaw gateway start" --name openclaw-discord
pm2 save && pm2 startupRelated Guides
Fix OpenClaw Browser Errors
Troubleshoot browser service disconnected and navigation failed errors
OpenClaw Autonomous Agent Setup
Deploy agents that run independently without manual input
OpenClaw Agent Communication
How agents collaborate using mentions and delegation patterns
OpenClaw GitHub Repository Guide
Navigate the codebase, clone, install, and contribute
Frequently Asked Questions
How do I connect OpenClaw to Discord?
Create a Discord application at discord.com/developers/applications, add a bot, copy the bot token, and run 'openclaw config set channels.discord.bottoken YOUR_TOKEN'. Enable the Message Content Intent in the bot settings, generate an OAuth2 invite link with the 'bot' scope and required permissions, add the bot to your server, then restart the gateway with 'openclaw gateway restart'. Your agent will start responding to messages in channels where the bot has access.
Why does my OpenClaw Discord bot keep disconnecting?
Discord bot disconnections are usually caused by three things: your host machine going to sleep, the gateway process being killed by the OOM killer on low-memory systems, or Discord's own rate limiting kicking in after too many API calls. On Mac, use 'caffeinate -i openclaw gateway start' to prevent sleep. On Linux, check 'dmesg | grep oom' for kill events. For rate limits, reduce message frequency or add a delay between responses. OpenClaw's built-in reconnection logic handles most transient disconnects automatically within 5-15 seconds.
What is the Lotus error in OpenClaw Discord integration?
The 'Lotus' error appears when OpenClaw's Discord channel adapter fails to authenticate with the Discord Gateway WebSocket. It typically means your bot token is invalid, expired, or has been regenerated in the Discord Developer Portal without updating the OpenClaw config. The fix is to go to the Developer Portal, regenerate the bot token, and update it with 'openclaw config set channels.discord.bottoken NEW_TOKEN' followed by 'openclaw gateway restart'.
Can one OpenClaw agent be in multiple Discord servers?
Yes. A single Discord bot can be added to as many servers as you want. Each server invite uses the same OAuth2 URL. The OpenClaw gateway maintains separate conversation contexts per channel and per server, so conversations in Server A do not leak into Server B. The agent uses the same SOUL.md configuration across all servers. If you need different behavior per server, run separate OpenClaw agents with different SOUL.md files and different bot tokens.
Does OpenClaw support Discord slash commands?
OpenClaw does not register Discord slash commands automatically. By default, the bot responds to regular text messages in channels where it has access. However, you can register slash commands manually through the Discord Developer Portal or with a script using the Discord API. Community members have shared examples of registering /ask and /report commands that forward the input to the OpenClaw agent and return the response as an ephemeral or channel message.
How do I make my OpenClaw bot respond only when mentioned in Discord?
Set the mention-only mode in your OpenClaw configuration: 'openclaw config set channels.discord.mentionOnly true'. With this enabled, the bot will only process messages that include an @mention of the bot. All other messages in the channel are ignored. This is the recommended setting for busy servers where you do not want the bot responding to every message.
What Discord permissions does an OpenClaw bot need?
At minimum, the bot needs Send Messages, Read Message History, and View Channels. If you want the bot to use embeds for formatted responses, add Embed Links. For file attachments (like reports or charts), add Attach Files. If the bot needs to manage threads, add Create Public Threads and Send Messages in Threads. The recommended permission integer for a standard OpenClaw agent is 277025770560, which covers all common use cases without granting admin-level access.
Build and Deploy Your Discord Agent
Get a complete, pre-configured OpenClaw agent with SOUL.md, Discord integration, deployment scripts, and monitoring. Start with a template and customize it for your server.