← Back to PRs

#22611: fix(discord): allow messages from other instance bots in multi-account setups

by dae-sun open 2026-02-21 11:24 View on GitHub →
channel: discord size: S
## 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