#22611: fix(discord): allow messages from other instance bots in multi-account setups
channel: discord
size: S
Cluster:
Signal and Discord Fixes
## Summary
Fixes #11199
In multi-agent setups with multiple Discord bot accounts (one per agent), messages from Bot A were incorrectly filtered by Bot B's handler because `allowBots` defaults to `false`, which blocks **all** bot messages — including those from other agents in the same OpenClaw instance.
## Root Cause
The `allowBots` check in `message-handler.preflight.ts` treats all bot messages uniformly. When `allowBots: false` (default), it drops messages from ANY bot, including sibling agent bots in the same instance. The self-message check (`author.id === params.botUserId`) correctly only filters the current account's own bot, but the broader `allowBots` gate blocks inter-agent messages before they can be processed.
## Fix
Introduces a module-level **instance bot user ID registry** that tracks all bot accounts managed by this OpenClaw instance:
- **`instance-bot-registry.ts`**: A `Set<string>` that stores bot user IDs registered by each account on startup
- **`provider.ts`**: Registers bot user ID after `fetchUser('@me')`, unregisters on shutdown
- **`message-handler.preflight.ts`**: When `allowBots: false`, skips the filter for messages from other bots in the same instance (`isInstanceBotUserId()`), while still blocking external bot messages
### Behavior Matrix
| Message From | `allowBots: false` (before) | `allowBots: false` (after) |
|---|---|---|
| Own bot | ✅ Filtered | ✅ Filtered |
| Other instance bot | ❌ Filtered (bug) | ✅ Allowed |
| External bot | ✅ Filtered | ✅ Filtered |
## Tests
5 unit tests in `instance-bot-registry.test.ts`:
- Register and detect instance bot user IDs
- Exclude own bot ID from instance check
- Unregister bot user IDs
- Handle empty/falsy inputs
- Clear all registrations
All tests passing.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Introduces a module-level bot user ID registry to enable multi-agent Discord communication. When `allowBots: false` (default), messages from bots in the same OpenClaw instance are now correctly allowed while external bot messages remain filtered. The fix properly distinguishes between same-instance bots (Bot A → Bot B communication) and external bots by tracking all bot user IDs in a shared `Set`. Registration happens during provider startup after `fetchUser('@me')` and before message listeners are attached, preventing race conditions. Cleanup is handled in the finally block during shutdown.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- Clean, focused solution with proper lifecycle management, comprehensive test coverage, and no race conditions. The module-level registry pattern is appropriate for tracking cross-instance state, and the implementation correctly distinguishes between self-messages (already filtered), instance bots (now allowed), and external bots (still filtered).
- No files require special attention
<sub>Last reviewed commit: 7b976ec</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
79.4%
#23689: feat(discord): add ignoreOtherMentions config option
by Q00 · 2026-02-22
79.1%
#16801: fix: Register Discord listeners before gateway connects
by MisterGuy420 · 2026-02-15
77.0%
#15900: fix(discord): filter bot's own messages early to prevent self-DoS
by Shuai-DaiDai · 2026-02-14
76.8%
#16685: Fix cli agents/approvals/discord routing edge cases
by craftowen · 2026-02-15
76.8%
#16736: fix: stagger multi-account channel startup to avoid Discord rate li...
by rm289 · 2026-02-15
76.8%
#19567: Fix: tighten Slack multi-account event filtering via api_app_id
by TARS-Nolan · 2026-02-17
76.6%
#13829: fix(googlechat): detect bot @mentions via user.type when botUser no...
by mcaxtr · 2026-02-11
76.5%
#11347: fix: scope Telegram update offset to bot token
by anooprdawar · 2026-02-07
75.4%
#15863: fix: route agent-to-agent Slack messages to bound sessions
by MisterGuy420 · 2026-02-14
75.3%