Connect Your Agent to Discord with Claude Code
Connect Your Agent to Discord with Claude Code
What you'll build
An OpenClaw agent on Discord with three specialized channels — research, coding, and general — each with different AI models and behaviors.
The Problem
Telegram is great for quick messages. But when you're juggling three projects, one chat thread becomes a mess. Your research question from Tuesday is buried under a coding task from Thursday and a writing request from this morning. You need structure.
What You're Building
A Discord server where your agent acts differently in each channel. #research gives thorough, sourced answers. #coding writes clean code. #general responds fast. Same bot, three specialists.
Milestone 1: Create a Discord Bot
Discord bots work like Telegram bots — you create one through a developer portal and get a token.
Walk me through creating a Discord bot step by step. I need to: 1) Go to the Discord Developer Portal, 2) Create a new application, 3) Add a bot to it, 4) Get the bot token, 5) Generate an invite link with the right permissions (send messages, read messages, manage channels). Then help me invite the bot to my Discord server.
What Claude Code does: It guides you through Discord's developer portal to create a bot application. Discord bots need explicit permissions — unlike Telegram where bots have broad access by default, Discord requires you to specify exactly what the bot can do. Claude Code generates the invite URL with the right permission flags.
Try it: Your bot should appear in your Discord server's member list as "offline" — it'll come online once we connect OpenClaw.
Milestone 2: Connect OpenClaw to Discord
Your bot exists on Discord but OpenClaw doesn't know about it yet.
Add Discord as a channel in my OpenClaw config at ~/.openclaw/openclaw.json. Use the bot token I just got. Enable the Discord channel, set it to require mentions in group channels (so the bot only responds when tagged), and allow direct messages. Keep my existing Telegram config intact.
What Claude Code does: It adds the Discord channel block to your config alongside Telegram. OpenClaw supports 50+ messaging platforms simultaneously — adding Discord doesn't replace Telegram. The requireMention: true setting means the bot stays quiet in channels unless someone @mentions it.
Try it: Restart the gateway (openclaw gateway restart) and check status. Discord should show as "connected." Your bot should appear online.
Milestone 3: Set Up Specialized Channels
One server, three channels, three purposes.
Create three channels in my Discord server using the Discord API or walk me through doing it manually: #research (for web lookups and information gathering), #coding (for code generation and debugging), and #general (for everything else). Then update my OpenClaw config to recognize each channel with its own settings.
What Claude Code does: It helps you create the channels and maps each one in your OpenClaw config. Each Discord channel gets its own configuration block — you can set different system prompts, different models, different skills, and different response styles per channel. The channel ID is the key that links Discord's structure to OpenClaw's routing.
Try it: You should see three new channels in your Discord server. Each one is a dedicated workspace for a different type of task.
Milestone 4: Configure Channel-Specific Behaviors
The channels exist but the agent acts the same in all of them. Let's fix that.
Update my OpenClaw config to give each Discord channel a different personality and model. For #research: use Gemini (if configured from Lesson 3) or Sonnet, add a system prompt that says "You are a research assistant. Provide sources and citations. Be thorough." For #coding: use Sonnet, add a system prompt that says "You are a coding assistant. Write clean code, explain your approach briefly, always include how to test." For #general: use Haiku for fast responses, keep the default personality.
What Claude Code does: It adds per-channel overrides to your Discord config. OpenClaw lets you define system prompts, models, and behaviors at the channel level — the same bot appears in all three channels but thinks and responds differently in each.
Try it: @mention your bot in each channel with the same question: "Explain recursion." You should get three different styles of answer — thorough in #research, code-focused in #coding, brief in #general.
Milestone 5: Test Multi-Channel Routing
Everything is configured. Let's verify the full setup.
Show me the OpenClaw logs filtered by Discord channel. I'm going to send messages in all three channels — I want to verify that each one uses the correct model and system prompt. Show me which model processes each message.
What Claude Code does: It opens filtered logs so you can verify routing. The logs show the full routing decision for every message — which channel it came from, which agent handled it, which model processed it, and what system prompt was active.
Try it: Send a message in each channel. Check the logs — you should see three different model names processing three different requests. Same bot, three specialists.
What You Built
Remember that single Telegram chat where everything blurred together? You now have a structured workspace on Discord where:
- #research gives thorough, sourced answers
- #coding writes clean code with test instructions
- #general responds fast for quick questions
- Each channel uses the optimal model for its purpose
- The bot only responds when mentioned, so it doesn't interrupt conversations
You just built a multi-specialist AI team. In one Discord server.
Take It Further
- Add a #writing channel — with Opus and a creative writing system prompt
- Create team access — invite colleagues to specific channels for shared AI workflows
- Build a mission control dashboard — see all agent activity across channels (that's Lesson 6)
Ready to build your first AI agent?
Live Zoom workshop + 1 month WhatsApp follow-up with Yuval Keshtcher (Hebrew)
Learn about the Workshop