Home Tutorials Categories Skills About
ZH EN JA KO
Channels

Complete Guide to Connecting OpenClaw with Discord

· 18 min read

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

  1. Click the New Application button in the top right corner
  2. Enter an application name, such as "OpenClaw Assistant"
  3. Check the box to agree to the developer terms of service
  4. Click Create

1.3 Create a Bot

  1. Click Bot in the left sidebar
  2. Click Add Bot and confirm the creation
  3. 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 OAuth2URL Generator in the left sidebar:

  1. Under Scopes, check: bot and applications.commands
  2. 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)
  1. Copy the generated URL

2.2 Invite to Server

  1. Open the URL copied in the previous step in your browser
  2. Select the server to add the Bot to
  3. Confirm the permissions and click Authorize
  4. 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:

  1. Create an application and Bot in the Discord Developer Portal
  2. Enable Message Content Intent
  3. Generate an invite link and invite the Bot to your server
  4. Enter the Token in the OpenClaw configuration file
  5. Restart the service and verify the connection

Once deployed, your Discord community will have a powerful AI assistant at its disposal.

OpenClaw is a free, open-source personal AI assistant that supports WhatsApp, Telegram, Discord, and many more platforms