Introduction
Discord is one of the most popular community communication platforms in the world. By connecting OpenClaw to Discord, you can deploy an intelligent AI assistant in your server to provide instant help to community members. This article walks you through the entire process, from creating a Discord Bot to connecting it with OpenClaw.
Prerequisites
Before you begin, make sure:
- OpenClaw is installed and running (
openclaw up) - You have a Discord account
- You have admin permissions on the target Discord server
Step 1: Create a Discord Application and Bot
1.1 Access the Developer Portal
Visit the Discord Developer Portal and log in with your Discord account.
1.2 Create a New Application
- Click the New Application button in the top right corner
- Enter an application name, such as "OpenClaw Assistant"
- Check the box to agree to the developer terms of service
- Click Create
1.3 Create a Bot
- Click Bot in the left sidebar
- Click Add Bot and confirm the creation
- On the Bot settings page:
- Set the Bot's avatar and username
- Click Reset Token to obtain the Bot Token
- Save the Token securely; you will need it for configuration
Note: The Bot Token is sensitive information. Never expose it or commit it to a public repository.
If it is accidentally leaked, reset the Token immediately in the Developer Portal.
1.4 Configure Privileged Intents
At the bottom of the Bot settings page, enable the following Privileged Gateway Intents:
| Intent | Description | Required |
|---|---|---|
| Presence Intent | Detect member online status | Optional |
| Server Members Intent | Access the member list | Optional |
| Message Content Intent | Read message content | Required |
Message Content Intent must be enabled, otherwise the Bot cannot read the content of user messages.
Step 2: Invite the Bot to Your Server
2.1 Generate an Invite Link
Click OAuth2 → URL Generator in the left sidebar:
- Under Scopes, check:
botandapplications.commands - Under Bot Permissions, check the following:
Required permissions:
├── Send Messages - Send messages
├── Send Messages in Threads - Send messages in threads
├── Embed Links - Embed links
├── Attach Files - Attach files
├── Read Message History - Read message history
├── Use Slash Commands - Use slash commands
├── Add Reactions - Add reactions
└── Manage Messages - Manage messages (optional, for deleting own messages)
- Copy the generated URL
2.2 Invite to Server
- Open the URL copied in the previous step in your browser
- Select the server to add the Bot to
- Confirm the permissions and click Authorize
- Complete the CAPTCHA verification
After a successful invitation, the Bot will appear in the server's member list (shown as offline since it is not yet connected to OpenClaw).
Step 3: Configure OpenClaw
3.1 Via Configuration File
Edit ~/.config/openclaw/openclaw.json5:
{
channels: {
discord: {
enabled: true,
// Bot Token obtained from the Developer Portal
botToken: "MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
// Obtained from the OAuth2 page in the Developer Portal
clientId: "123456789012345678",
// Trigger configuration
trigger: {
// Whether @Bot is required to trigger a reply (false means all messages get a reply)
mentionRequired: true,
// Custom trigger prefix (optional)
prefix: "!ask",
// Whether to respond to direct messages
dmEnabled: true
},
// Reply settings
reply: {
// Whether to reply in Embed format
useEmbed: true,
// Embed color (hexadecimal)
embedColor: "#5865F2",
// Whether to automatically follow up replies in threads
threadReply: true,
// Character count for auto-splitting long messages
maxLength: 2000
}
}
}
}
3.2 Via Environment Variables
export DISCORD_BOT_TOKEN="MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.XXXXXX.XXXX"
export DISCORD_CLIENT_ID="123456789012345678"
3.3 Restart the Service
After configuration, restart OpenClaw:
openclaw restart
Check the logs to confirm the connection status:
openclaw logs -f --component channel:discord
Upon successful connection, the logs will show:
[INFO] [channel:discord] Bot logged in as OpenClaw Assistant#1234
[INFO] [channel:discord] Connected to 3 servers
[INFO] [channel:discord] Slash commands registered
Step 4: Configure Slash Commands
OpenClaw supports registering Discord Slash Commands, allowing users to trigger specific features via /.
Default Slash Commands
After a successful connection, OpenClaw automatically registers the following slash commands:
| Command | Description |
|---|---|
/ask <question> |
Ask the AI a question |
/model <model_name> |
Switch the current AI model |
/reset |
Reset the conversation context |
/help |
Display help information |
Custom Slash Commands
You can add custom commands in the configuration file:
{
channels: {
discord: {
// ...other configuration
slashCommands: [
{
name: "translate",
description: "Translate text",
options: [
{
name: "text",
description: "Text to translate",
type: "STRING",
required: true
},
{
name: "language",
description: "Target language",
type: "STRING",
required: false,
choices: [
{ name: "中文", value: "zh" },
{ name: "English", value: "en" },
{ name: "日本語", value: "ja" }
]
}
],
// Associated skill or system prompt
skill: "translate"
}
]
}
}
}
Multi-Server Configuration
When the Bot is invited to multiple Discord servers, you can set different behaviors for each server:
{
channels: {
discord: {
enabled: true,
botToken: "your-bot-token",
clientId: "your-client-id",
// Server-level configuration
guilds: {
// Server ID: configuration
"111111111111111111": {
model: "claude",
systemPrompt: "You are a technical support assistant",
allowedChannels: ["general", "bot-chat"],
trigger: { mentionRequired: false }
},
"222222222222222222": {
model: "gpt-4o",
systemPrompt: "You are a friendly chat companion",
allowedChannels: ["ai-chat"],
trigger: { mentionRequired: true }
}
},
// Servers not listed in guilds will use the default settings
defaultGuild: {
model: "claude",
trigger: { mentionRequired: true }
}
}
}
}
To get a server ID: enable Developer Mode in Discord (Settings > Advanced > Developer Mode), then right-click the server icon and select "Copy Server ID."
Embed Formatting
OpenClaw supports formatting replies as Discord Embeds for a more polished appearance:
{
channels: {
discord: {
reply: {
useEmbed: true,
embedColor: "#5865F2",
embedFooter: "Powered by OpenClaw",
// Automatic syntax highlighting for code blocks
codeHighlight: true,
// Automatically split long replies into multiple Embeds
splitEmbed: true
}
}
}
}
Embed features include:
- Colored sidebar indicating AI replies
- Syntax highlighting for code blocks
- Footer showing model name and token consumption
- Automatic pagination for long content
Troubleshooting
Bot Shows as Offline
# Check if the Token is correct
openclaw config get channels.discord.botToken
# Check error messages in the logs
openclaw logs --level error --component channel:discord
Common causes: incorrect Token, expired Token, or network connectivity issues.
Bot Does Not Respond to Messages
# Confirm Message Content Intent is enabled
# Check in Developer Portal → Bot → Privileged Gateway Intents
Insufficient Permissions Error
Make sure the Bot has permission to send messages in the target channel. You can check the Bot role's permission settings in the Discord server configuration.
Summary
Discord integration is one of the most commonly used channels in OpenClaw. Here is a recap of the key steps:
- Create an application and Bot in the Discord Developer Portal
- Enable Message Content Intent
- Generate an invite link and invite the Bot to your server
- Enter the Token in the OpenClaw configuration file
- Restart the service and verify the connection
Once deployed, your Discord community will have a powerful AI assistant at its disposal.