channels··6 min read

Setting Up an OpenClaw Discord Bot: Step-by-Step

Learn how to create a Discord bot and connect it to your OpenClaw instance so your team can interact with AI directly from Discord channels.

ST
SimpleOpenClaw Team

Discord is where many development teams already spend their time. By connecting OpenClaw to a Discord bot, your team can interact with the AI coding assistant without leaving their communication platform. This tutorial covers the entire process from creating a Discord application to verifying the bot responds in your server.

What You'll Need

Before starting, make sure you have:

  • A running OpenClaw instance (deployed on Railway or self-hosted)
  • Administrator access to a Discord server
  • A Discord account that can create applications in the Discord Developer Portal

Step 1: Create a Discord Application

Navigate to the Discord Developer Portal and click "New Application." Give it a meaningful name like "OpenClaw Assistant" -- this name appears in the bot's profile.

On the General Information page, note down the Application ID. You'll need this later, but the critical piece comes from the Bot section.

Step 2: Create the Bot User

In your application's settings, navigate to the "Bot" section in the left sidebar. Click "Add Bot" and confirm. This creates the actual bot user that will appear in your Discord server.

Configure Bot Settings

Before copying the token, configure these important settings:

  • Public Bot: Disable this unless you want anyone to add your bot to their server
  • Message Content Intent: Enable this -- this is critical. Without the Message Content Intent, your bot cannot read message content in servers, which means it cannot process user prompts. This is the single most common cause of "the bot is online but doesn't respond" issues.

Copy the Bot Token

Click "Reset Token" to generate a new bot token. Copy it immediately and store it securely -- Discord only shows it once. This token is essentially the bot's password. Anyone with this token can control the bot, so never commit it to version control or share it publicly.

Step 3: Set Bot Permissions

Navigate to the "OAuth2" section and then "URL Generator." Select the following scopes:

  • bot
  • applications.commands (if you plan to use slash commands)

Under Bot Permissions, select at minimum:

  • Read Messages/View Channels -- the bot needs to see messages directed at it
  • Send Messages -- the bot needs to respond
  • Send Messages in Threads -- if your team uses threads
  • Embed Links -- allows rich formatting in responses
  • Read Message History -- enables context from previous messages

The URL Generator produces an invite link. Copy this link for the next step.

Step 4: Add the Bot to Your Server

Open the invite link from the previous step in your browser. Discord will prompt you to select a server. Choose your target server (you must have "Manage Server" permission) and authorize the requested permissions.

After authorization, the bot appears in your server's member list, but it will show as offline. That's expected -- it doesn't come alive until OpenClaw connects to it.

Step 5: Configure OpenClaw

Now connect your OpenClaw instance to the Discord bot. You have two options.

Option A: Using the Setup Wizard

Navigate to your OpenClaw instance's /setup page. In the channels configuration section, select "Discord" and enter the bot token you copied in Step 2.

The setup wizard writes the channel configuration to openclaw.json and restarts the gateway to apply the changes. Within a few seconds, your bot should appear as online in Discord.

Option B: Manual Configuration

If you prefer to configure channels after initial setup, you can use the OpenClaw CLI within the container. The wrapper writes channel configurations using openclaw config set --json, which directly modifies the configuration file.

The channel configuration needs:

  • Bot Token: The token from Step 2
  • Channel Type: discord

After updating the configuration, restart the gateway process for changes to take effect.

Step 6: Verify the Connection

Go to your Discord server and find a channel where the bot has permissions. Send a message that mentions the bot or uses whatever trigger pattern your configuration specifies. The bot should respond with an AI-generated reply within a few seconds.

Testing Checklist

Run through these verifications to confirm everything is working:

  1. Bot shows as online in the server member list
  2. Direct messages work: Send a DM to the bot and verify it responds
  3. Channel messages work: Mention the bot in a channel and verify the response
  4. Long responses render correctly: Ask a question that generates a multi-paragraph response
  5. Code blocks format properly: Ask the bot to write a code snippet and verify Discord renders it with syntax highlighting

Troubleshooting Common Issues

Bot Is Online But Doesn't Respond

This is almost always the Message Content Intent issue. Return to the Discord Developer Portal, go to your application's Bot settings, and verify that "Message Content Intent" is enabled. After enabling it, restart the OpenClaw gateway.

Bot Responds With Errors

Check your OpenClaw instance logs for error messages. The most common cause is an expired or invalid AI provider API key. The Discord bot is just a transport layer -- if the underlying AI provider fails, the bot relays the error.

Bot Goes Offline Periodically

Discord requires bots to maintain a heartbeat connection. If your OpenClaw instance restarts (due to deployment updates, resource limits, or crashes), the bot temporarily disconnects. It should reconnect automatically once the gateway restarts. If it doesn't, check the gateway logs for Discord-specific connection errors.

Rate Limiting

Discord enforces rate limits on bot messages. If your bot sends too many messages in a short period, Discord will temporarily throttle it. This is rarely an issue in normal usage but can occur if multiple users send prompts simultaneously.

Security Considerations

Token Rotation

If you suspect your bot token has been compromised, immediately go to the Discord Developer Portal and reset it. Update the token in your OpenClaw configuration and restart the gateway.

Channel Restrictions

Consider restricting the bot to specific channels rather than giving it server-wide access. This prevents accidental AI interactions in channels where they're not appropriate and reduces noise for team members who don't need the bot.

Audit Logging

All interactions with the bot flow through your OpenClaw instance, so your instance logs serve as an audit trail. For teams with compliance requirements, ensure these logs are retained appropriately.

Conclusion

A Discord integration transforms OpenClaw from a standalone tool into a team resource embedded in your existing workflow. The setup takes about fifteen minutes, and once running, the bot operates transparently -- team members interact with it just like they would with any other Discord bot, but with the full capabilities of your AI coding assistant behind it.

discordbotintegration

Related Articles