Clawist
Beginner12 min readBy Lin6

Building a Discord Bot with OpenClaw: Complete Tutorial

Discord bots powered by OpenClaw combine the conversational intelligence of Claude AI with Discord's rich platform features. Unlike traditional bots that require extensive coding for each command, OpenClaw bots understand natural language and can perform complex tasks through simple instructions.

This tutorial walks you through creating a Discord bot from scratch, connecting it to OpenClaw, and building features like custom commands, automated moderation, and scheduled announcements.

Why OpenClaw for Discord Bots

Traditional Discord bots require writing code for every single command and interaction. Want to add a new feature? Write more code, test it, deploy it. This development cycle is slow and requires programming knowledge.

OpenClaw bots work differently. They use Claude's language understanding to interpret commands flexibly. Instead of rigid command structures like !weather 10001, users can ask "What's the weather like in NYC?" and the bot understands. You define bot behavior in natural language instructions, not code.

The bot has access to OpenClaw's entire skill ecosystem. It can browse the web, manage files, interact with APIs, and orchestrate workflows—all without custom integration work. Need your bot to search GitHub, create issues, and notify your team? That's three lines of instructions, not three libraries and authentication flows.

Setting Up Discord Developer Portal

Before connecting OpenClaw, you need to create a Discord application and bot user. Head to the Discord Developer Portal and log in with your Discord account.

Click "New Application" and give it a descriptive name. This becomes your bot's identity, so choose something that matches its purpose—like "TeamHelper" for a productivity bot or "ContentBot" for a social media manager.

Navigate to the "Bot" section in the left sidebar and click "Add Bot". This creates the bot user that will appear in your Discord server. Under the bot's username, you'll see a "Token" section. Click "Reset Token" and copy the token immediately—you'll need this for OpenClaw.

Important security note: Never share this token publicly or commit it to git. Anyone with the token can control your bot completely. Store it in an environment variable or OpenClaw's secret manager.

Configuring Bot Permissions

Discord bots need explicit permissions for every action they take. Under the "Bot" section, scroll to "Privileged Gateway Intents" and enable:

  • Presence Intent: Lets the bot see who's online
  • Server Members Intent: Access to member join/leave events
  • Message Content Intent: Required to read message text (critical for AI bots)

Without Message Content Intent, your bot can see that messages exist but not what they say—making AI responses impossible.

Next, go to the "OAuth2" > "URL Generator" section. Select these scopes:

  • bot
  • applications.commands

Then select permissions based on what your bot needs:

  • Read Messages/View Channels: See messages and channels
  • Send Messages: Reply to users
  • Manage Messages: Delete messages (for moderation)
  • Embed Links: Send rich embedded content
  • Attach Files: Share images and documents
  • Add Reactions: React to messages with emoji
  • Manage Channels: Create/edit channels (optional)
  • Manage Roles: Assign roles (optional)

Discord generates an OAuth URL at the bottom. Copy this URL and open it in your browser to add the bot to your server. Select which server to add it to, and authorize the permissions.

Connecting OpenClaw to Discord

OpenClaw's Discord integration uses the message channel system. Configure a new channel that connects to your Discord bot token.

Create a channel configuration file:

mkdir -p ~/.openclaw/channels
nano ~/.openclaw/channels/discord-bot.yaml

Add your bot configuration:

type: discord
token: YOUR_BOT_TOKEN_HERE
guildId: YOUR_SERVER_ID  # optional, for guild-specific bots
defaultChannel: general   # where the bot listens by default

Find your server (guild) ID by enabling Developer Mode in Discord (Settings > Advanced > Developer Mode), then right-clicking your server icon and selecting "Copy ID".

Restart the OpenClaw gateway to load the new channel:

openclaw gateway restart

Your bot should now appear online in your Discord server. It's connected to OpenClaw and ready to respond.

Creating Your First Bot Command

OpenClaw bots respond to @mentions by default. Try mentioning your bot with a question:

@YourBot what's the weather in San Francisco?

The bot uses Claude to understand the intent, calls appropriate tools (in this case, web search or a weather API), and responds conversationally.

To create custom behavior, add instructions to the bot's system prompt. Create a bot persona file:

nano ~/.openclaw/workspace/discord-bot-instructions.md

Define how your bot should behave:

# Discord Bot Instructions

You are a helpful team assistant for a software development team.

## Your capabilities:
- Answer questions about projects
- Search documentation
- Create GitHub issues
- Schedule reminders
- Moderate conversations

## Your personality:
- Professional but friendly
- Use emoji sparingly (👍 ✅ 🚀 only)
- Keep responses concise (under 200 words unless asked for details)
- When you don't know something, say so clearly

## Special commands:
- "deploy status" → check deployment pipeline status
- "create issue" → walk user through creating a GitHub issue
- "docs for X" → search internal documentation

Link this to your OpenClaw agent configuration so the bot loads these instructions on startup.

Building Advanced Bot Features

Automated responses trigger on keywords or patterns without @mentions. Configure these in your bot instructions:

## Automatic responses (no @mention needed):

When someone says "good morning" in #general → respond with "Good morning! ☀️"
When someone posts a link to stackoverflow.com → react with 👀
When someone says "deploy" in #deployments → post current deployment status

OpenClaw monitors all messages in channels where the bot has access and executes matching instructions automatically.

Role-based permissions restrict bot features to specific users or roles:

## Permissions:

Only users with "Admin" role can:
- Execute deployment commands
- Modify bot settings
- Access server logs

Only users with "Developer" role can:
- Create GitHub issues
- Search private docs
- Trigger build pipelines

Everyone can:
- Ask general questions
- Search public docs
- Get help

Claude checks the user's roles before executing sensitive commands, responding with "You need the Developer role to use this command" if unauthorized.

Scheduled announcements post messages at specific times. Use OpenClaw's cron system:

openclaw cron create "Daily standup reminder" \
  --schedule "0 9 * * 1-5" \
  --command "Send message to Discord #general: 'Daily standup starts in 30 minutes! 🎤'"

This posts to the #general channel at 9 AM every weekday. The bot can pull information from calendars, check task status, or aggregate updates before posting.

Moderation and Safety Features

Discord bots can help moderate communities automatically. OpenClaw bots use Claude's understanding of context to identify problematic content more accurately than keyword filters.

Configure moderation rules in your bot instructions:

## Moderation rules:

Monitor all channels for:
- Spam (repeated identical messages)
- Harassment or personal attacks
- External links from new users (< 1 week old)
- @everyone/@here abuse

When detected:
1. Delete the offending message
2. Send a DM to the user explaining why
3. Log the incident in #mod-log
4. If severe or repeated, notify moderators in #mod-alerts

The bot evaluates messages in context, reducing false positives. Unlike rigid keyword filters, it understands that "this is stupid" about a bug is different from "you're stupid" directed at a person.

Configuring sensitivity levels:

  • Low: Only flag clear violations
  • Medium: Flag potential issues for moderator review
  • High: Proactively remove borderline content

Start with medium sensitivity and adjust based on your community's needs.

Integrating with External Services

OpenClaw bots can interact with any service that has an API or webhook. Common integrations include:

GitHub: Create issues, check PR status, trigger workflows

When someone says "create issue" in #bugs:
1. Ask for title and description
2. Create GitHub issue in the project repository
3. Reply with the issue number and URL

Google Calendar: Schedule events, check availability

When someone says "schedule meeting":
1. Ask for date, time, and duration
2. Check team availability in Google Calendar
3. Create the calendar event
4. Post confirmation in the channel

Jira: Track tasks, update status

When someone references a Jira ticket like "PROJ-123":
1. Fetch the ticket details
2. Post a summary with status and assignee
3. Provide a direct link

Analytics: Report metrics and insights

When someone asks "traffic today":
1. Query Google Analytics for today's sessions
2. Compare to yesterday and last week
3. Post a summary with key metrics

Set up API credentials in OpenClaw's secret manager, and the bot handles authentication automatically.

Handling Errors Gracefully

Bots encounter errors—APIs go down, rate limits hit, permissions change. Configure how your bot handles failures:

## Error handling:

When a command fails:
1. Don't expose technical error details to users
2. Reply with a friendly explanation
3. Log the full error to #bot-errors for debugging
4. If critical, notify the bot administrator

Example responses:
- "Sorry, I couldn't reach GitHub right now. Try again in a minute?"
- "I don't have permission to do that. An admin needs to update my role."
- "That command timed out. The API might be slow right now."

Users appreciate transparency without confusion. "The API returned a 503" means nothing to most people; "The service is temporarily down" does.

Testing Your Bot

Before deploying bot features to your main server, test in a private Discord server. Create a test server with a few channels that mirror your production setup.

Common testing scenarios:

  • Permission checks: Do role restrictions work correctly?
  • Error handling: What happens when APIs are unreachable?
  • Rate limits: Can the bot handle message floods?
  • Command parsing: Does it understand variations of commands?

Invite a few team members to the test server to try breaking the bot. They'll find edge cases you didn't consider.

Optimizing Bot Performance

Discord has rate limits—bots can only send messages so frequently. OpenClaw handles rate limiting automatically, but you can optimize:

Batch responses: Instead of replying to each message individually during busy periods, batch updates:

When multiple people ask similar questions within 2 minutes:
- Collect all the questions
- Post one comprehensive answer that addresses all of them
- Mention each person who asked

Use reactions instead of messages: For simple acknowledgments, react with emoji rather than posting a message. This reduces channel clutter and API calls.

Cache frequent queries: If users repeatedly ask the same thing ("what's the deploy status?"), cache the result for 60 seconds rather than hitting the API each time.

Monitoring and Analytics

Track how your bot is used to improve it over time. OpenClaw provides built-in analytics for message volume, command usage, and error rates.

Key metrics to monitor:

  • Most used commands: Focus development on popular features
  • Error rate: High errors indicate problems needing fixes
  • Response time: Slow responses suggest performance issues
  • Active users: Who's using the bot most?

Export analytics to a dashboard or set up weekly summary reports. This data drives decisions about what features to add or remove.

Conclusion

OpenClaw Discord bots combine the flexibility of AI with Discord's powerful platform features. Unlike traditional bots that require code for every feature, you define behavior in natural language and let Claude handle execution.

Start simple—get the bot responding to @mentions and performing basic tasks. As you grow comfortable, add moderation, scheduled announcements, and external integrations. The natural language instruction system means you can iterate quickly without deployment cycles.

Your Discord community gets an intelligent assistant that understands context, learns from instructions, and integrates seamlessly with the tools you already use. That's the future of Discord bots.