Skip to main content

Clawdbot Integration

Clawdbot is an open-source Discord bot that brings Claude AI to your Discord server. You can configure it to use the LeanMCP AI Gateway for monitoring and cost tracking.
Video Tutorial: Watch the Clawdbot setup guide on YouTube for a visual walkthrough.

Prerequisites

1

Get Credits

Purchase credits at ship.leanmcp.com
2

Create API Key

Create an API key at ship.leanmcp.com/api-keys with SDK permissions
3

Clone Clawdbot

Clone or fork the Clawdbot repository:
git clone https://github.com/clawdbot/clawdbot.git
cd clawdbot

Configuration

Environment Variables

Configure your .env file with the LeanMCP AI Gateway:
# Discord Configuration
DISCORD_BOT_TOKEN=your_discord_bot_token

# AI Gateway Configuration (instead of direct Anthropic)
ANTHROPIC_API_KEY=leanmcp_your_api_key_here
ANTHROPIC_BASE_URL=https://aigateway.leanmcp.com/v1/anthropic

Configuration File

If Clawdbot uses a configuration file, update it to use the gateway:
{
  "anthropic": {
    "apiKey": "leanmcp_your_api_key_here",
    "baseUrl": "https://aigateway.leanmcp.com/v1/anthropic"
  }
}

How It Works

Discord User Message
        |
        v
    Clawdbot
        |
        v
  LeanMCP AI Gateway  <-- Logs request, checks for sensitive data
        |
        v
   Anthropic API
        |
        v
  Claude Response
        |
        v
  Discord Reply

Benefits for Discord Bots

User Monitoring

Track which Discord users are using the bot and how much

Cost Control

Set limits to prevent runaway costs from heavy usage

Content Filtering

Block inappropriate prompts before they reach Claude

Usage Analytics

Understand how your community uses the AI bot

Adding User Tracking

To track usage per Discord user, modify your Clawdbot code to include user headers:
// When making API calls, include the Discord user ID
const response = await anthropic.messages.create({
  model: 'claude-sonnet-4-5-20250929',
  messages: messages,
}, {
  headers: {
    'X-User-ID': message.author.id,
    'X-Server-ID': message.guild?.id,
    'X-Channel-ID': message.channel.id,
  }
});
This enables:
  • Per-user usage tracking in your dashboard
  • Setting limits per Discord user
  • Blocking specific users if needed

Verifying the Setup

  1. Start your Clawdbot instance
  2. Send a message to the bot in Discord
  3. Check your LeanMCP Dashboard to see the request
Clawdbot request logs

Setting Up Rate Limits

Protect your bot from abuse with rate limits:
// In your LeanMCP dashboard or via API
// Set per-user limits for Discord bot users
await leanmcp.gateway.setRateLimit({
  scope: 'per_user',
  limits: {
    requestsPerMinute: 5,
    requestsPerHour: 50,
    tokensPerDay: 100000,
  }
});

Troubleshooting

  • Check your Discord bot token is valid
  • Verify the LeanMCP API key has credits
  • Check Clawdbot logs for error messages
  • Ensure the base URL ends with /v1/anthropic (no trailing slash)
  • Verify your API key starts with leanmcp_
  • Check that you have sufficient credits
  • Confirm Clawdbot is using the custom base URL
  • Check environment variables are loaded correctly
  • Restart the bot after configuration changes

Resources

Next Steps