How to Build a Discord Bot With OpenClaw
A complete guide to building and deploying a Discord bot using OpenClaw ā covering gateway setup, slash commands, conversation memory, and how it compares to Telegram.
Discord has 600 million registered users and is no longer just for gamers ā it's where developer communities, DAOs, creator fan clubs, and B2B SaaS support channels live. If you want an AI agent that talks to people in Discord, OpenClaw is one of the cleanest ways to get there.
This guide walks you through the full setup: Discord application credentials, bot permissions, OpenClaw channel configuration, and deploying it somewhere that stays online.
What You're Building
An AI agent that:
- Responds to direct messages in Discord
- Can be added to servers and responds in specific channels
- Maintains per-user conversation memory
- Has a persona defined by your SOUL.md
Discord vs. Telegram: Which Should You Pick?
Both are fully supported by OpenClaw. Here's how they compare:
| Feature | Discord | Telegram |
|---|---|---|
| User base | Gamers, devs, communities | Global, strong in Asia/Eastern Europe |
| Bot API maturity | Good, REST-based | Excellent, very stable |
| Slash commands | Native, built-in UI | Via BotFather /commands |
| Group permissions | Granular role system | Basic admin/member |
| Message formatting | Markdown subset | Full HTML + Markdown |
| Setup complexity | Moderate (OAuth2 scopes) | Simple (just a token) |
Discord is better if your audience is a tech/gaming/creator community. Telegram wins for global reach and simpler bot setup. For internal tools (team bots, support channels), Discord's role-based permissions are hard to beat.
Step 1: Create a Discord Application
- Go to discord.com/developers/applications
- Click New Application, name it something like
SupportBot - Go to the Bot tab ā click Add Bot
- Under Token, click Reset Token and copy it
- Enable these Privileged Gateway Intents:
- ā Server Members Intent
- ā Message Content Intent (required to read messages in servers)
# Store this securely ā never commit to git
DISCORD_BOT_TOKEN=your_token_here
Keep that token secret. Rotating it invalidates all existing connections.
Step 2: Set Bot Permissions and Invite URL
In the OAuth2 ā URL Generator tab:
Scopes: bot, applications.commands
Bot Permissions:
- Read Messages / View Channels
- Send Messages
- Read Message History
- Add Reactions (optional, nice for UX)
Copy the generated URL and open it in your browser to invite the bot to your server.
Step 3: Configure OpenClaw for Discord
In your OpenClaw project, create or edit channels/discord.yaml:
channel:
type: discord
token: ${DISCORD_BOT_TOKEN}
respond_to_dms: true
respond_in_channels:
- "1234567890123456789" # channel IDs, or use "*" for all
ignore_bots: true
Restart your OpenClaw instance after saving. The bot should appear online in your server within a few seconds.
Step 4: Define Your Agent's Persona
Your SOUL.md is the personality layer. For a Discord support bot:
# DevHelper Bot
You are DevHelper, a technical support assistant for Acme SDK.
## Personality
- Friendly but precise. No filler phrases.
- Use code blocks when showing code. Always.
- If you don't know something, say so. Don't guess at API behavior.
## Scope
- Help with Acme SDK installation, configuration, and debugging
- Refer billing questions to the #billing channel
- For feature requests, link to github.com/acme/sdk/issues
## Tone
Discord is casual. Match the energy ā brief, helpful, human.
Don't start messages with "Certainly!" or "Great question!"
Step 5: Handling Slash Commands
OpenClaw supports slash command registration. Add this to your config:
slash_commands:
- name: "help"
description: "Show what this bot can do"
- name: "reset"
description: "Clear your conversation history"
- name: "status"
description: "Check bot status"
OpenClaw registers these with Discord on startup. Users get autocomplete in the Discord slash command UI automatically.
Step 6: Channel-Specific Behavior
Configure different behavior per channel type:
behaviors:
dm:
system_prompt: "You are a personal assistant. Be detailed."
memory: true
server_channel:
system_prompt: "You are a public support bot. Be concise."
memory: false
max_tokens: 500
This prevents the bot from writing essays in busy public channels while remaining thorough in DMs.
Step 7: Rate Limiting
Discord bots get spammed. Add limits in your config:
rate_limits:
per_user_per_minute: 10
per_channel_per_minute: 30
cooldown_message: "Slow down! Try again in a few seconds."
The Self-Hosting Reality
Running an OpenClaw Discord bot yourself means:
- A VPS or container with persistent uptime (Discord uses WebSocket gateway ā bots go offline if the process dies)
- Process supervisor (systemd, PM2, or Docker Compose) to handle restarts
- Log rotation, monitoring, alerting
- Manual token rotation when Discord forces it
On a $5/month VPS this works, but it's a weekend of setup per deployment, and you're the on-call engineer at 2am.
Testing Your Bot
Before shipping, test these scenarios:
1. DM the bot with a normal question ā should respond
2. DM the bot with an off-topic question ā should redirect
3. Flood the bot with 15 messages fast ā rate limit should trigger
4. Use /reset ā conversation memory should clear
5. Add the bot to a server channel ā should respond if channel is in allowlist
Use Discord's developer mode (Settings ā Advanced ā Developer Mode) to right-click and copy channel/user IDs for your config.
Common Issues
Bot appears offline but token is correct ā Check that Message Content Intent is enabled. Without it, the bot can't read messages in servers.
Bot responds in DMs but not in server channels
ā Check your respond_in_channels config. It must include the channel ID or "*".
Slash commands don't appear ā Discord takes up to an hour to propagate global slash commands. Use guild-specific commands during dev (instant propagation).
Try It on ClawPort
If you'd rather skip the VPS setup, ClawPort hosts your OpenClaw agent for $10/month. Paste in your Discord bot token, upload your SOUL.md, and it handles uptime, restarts, and environment variable management.
Seven-day free trial, no credit card required. The Discord channel takes about 3 minutes to configure from the dashboard.
What's Next
Once your Discord bot is running, consider:
- Webhooks to trigger actions in other systems when the bot receives certain messages
- Knowledge base integration by pointing the agent at your docs
- Lead collection via qualifying questions in DMs
Ready to deploy your AI agent?
Get started with ClawPort in 60 seconds. No credit card required.
Get Started FreeRelated Articles
Add an AI Chatbot to Your Shopify Store (Without Apps)
How to connect an OpenClaw agent to your Shopify store for product recommendations, order tracking, and FAQ automation ā without paying $50/month for a chatbot app.
How to Migrate From ChatGPT Assistants API to OpenClaw
Why developers are moving away from the OpenAI Assistants API, a full feature comparison, and step-by-step migration guide ā including conversation history, file search, and function calling.
Build an AI Appointment Booking Agent (Google Calendar + OpenClaw)
How to build an AI agent that checks availability, books appointments, and sends confirmations using Google Calendar ā ideal for service businesses, coaches, and consultants.
OpenClaw on Docker: Production Setup That Won't Get You Hacked
Most OpenClaw Docker tutorials give you a one-liner that works but leaves your server wide open. Here's the production-grade Docker Compose setup with bridge networking, resource limits, backups, and monitoring.