What We’re Building
An AI assistant that lives in your Discord server—capable of answering questions, running tasks, and integrating with your workflows.
What you’ll need:
- A Discord account
- A server where you’re admin
- About 15 minutes
Step 1: Create a Discord Bot
1.1 Access the Developer Portal
- Go to Discord Developer Portal
- Click “New Application”
- Name it (e.g., “MyAIAssistant”)
- Accept the terms
1.2 Enable Bot Functionality
- In your app, go to “Bot” section (left sidebar)
- Click “Add Bot”
- Confirm with “Yes, do it!”
1.3 Get Your Token
Critical: The bot token is like a password. Never share it or commit it to git.
- Under Bot section, click “Reset Token”
- Copy the new token (starts with something like
MTQ2N...) - Store it securely (password manager or env variable)
Step 2: Configure Bot Permissions
2.1 Privileged Gateway Intents
Enable these under Bot → Privileged Gateway Intents:
- ✅ MESSAGE CONTENT INTENT (required for reading messages)
- ✅ SERVER MEMBERS INTENT (for member-related features)
- ✅ PRESENCE INTENT (optional, for presence data)
Without MESSAGE CONTENT INTENT, your bot can’t see what people are saying.
2.2 OAuth2 Scopes
- Go to OAuth2 → URL Generator
- Select scopes:
botapplications.commands
- Select bot permissions:
- Send Messages
- Read Message History
- Embed Links
- Attach Files
- Add Reactions
- Use Slash Commands
2.3 Invite Bot to Server
- Copy the generated URL
- Open in browser
- Select your server
- Authorize
Step 3: Configure OpenClaw
3.1 Set Environment Variable
export DISCORD_BOT_TOKEN="your-token-here"
Or add to ~/.openclaw/.env:
DISCORD_BOT_TOKEN=your-token-here
3.2 Update hugo.toml
{
"channels": {
"discord": {
"enabled": true,
"token": "${env:DISCORD_BOT_TOKEN}",
"groupPolicy": "allowlist"
}
}
}
3.3 Configure Channel Permissions
Restrict which channels the bot can access:
"channels": {
"discord": {
"enabled": true,
"token": "${env:DISCORD_BOT_TOKEN}",
"groupPolicy": "allowlist",
"guilds": {
"YOUR_GUILD_ID": {
"channels": {
"CHANNEL_ID_1": { "allow": true },
"CHANNEL_ID_2": { "allow": true }
}
}
}
}
}
Finding IDs:
- Enable Developer Mode in Discord (Settings → Advanced)
- Right-click server → “Copy Server ID”
- Right-click channel → “Copy Channel ID”
Step 4: Test the Setup
4.1 Start OpenClaw
openclaw gateway restart
4.2 Check Logs
openclaw gateway status
# Or check systemd logs
journalctl --user -u openclaw-gateway -f
4.3 Test in Discord
- Go to an allowed channel
- Mention the bot:
@MyAIAssistant hello - Check for response
Common Issues
“401 Unauthorized”
Cause: Invalid or expired token
Fix:
- Reset token in Discord Developer Portal
- Update environment variable
- Restart gateway
“403 Forbidden”
Cause: Bot lacks permissions
Fix:
- Check OAuth2 URL generated correct permissions
- Re-invite bot with updated scope
- Verify MESSAGE CONTENT INTENT is enabled
“Cannot send messages”
Cause: Channel permissions override bot permissions
Fix:
- Check channel-specific permissions
- Ensure bot role is above restricted roles
- Verify bot is in the channel
Bot doesn’t respond
Checklist:
- Gateway running? (
openclaw gateway status) - Token correct? (check for extra spaces)
- Channel in allowlist? (if using groupPolicy)
- Bot has message read permission?
- Mentioning correctly? (@BotName)
Security Best Practices
- Never commit tokens – Use environment variables
- Use allowlists – Restrict to specific channels
- Rotate tokens periodically – Every 90 days
- Monitor bot activity – Check logs regularly
- Limit permissions – Only what’s necessary
What’s Next
Now that Discord is connected, you can:
- Set up scheduled tasks (cron jobs)
- Configure multiple channels for different purposes
- Add webhook integrations
- Set up DM responses
See the OpenClaw Discord docs for advanced features.
Full working configuration in the example above. Adjust channel IDs and token for your setup.