← Back to PRs

#16801: fix: Register Discord listeners before gateway connects

by MisterGuy420 open 2026-02-15 04:22 View on GitHub →
channel: discord stale size: S trusted-contributor
## Summary This fix addresses a race condition where MESSAGE_CREATE events could be missed if the gateway connected before Discord event listeners were registered. This issue is especially problematic on ARM64 platforms like Raspberry Pi where timing behaves differently. The fix ensures all Discord event listeners are created and passed to the Client constructor BEFORE the gateway plugin connects to Discord WebSocket. ## Changes - Create message handler, logger, and guildHistories before Client initialization - Create all event listeners before creating the Client - Pass all listeners to the Client constructor ## Testing - TypeScript compilation check passed - Code follows existing patterns Fixes openclaw/openclaw#16781 <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes a race condition where Discord MESSAGE_CREATE events could be missed on ARM64 platforms (like Raspberry Pi) by ensuring all event listeners are registered before the Client constructor is called, which triggers the gateway connection. The core refactoring moves listener creation earlier in the initialization sequence and passes them to the Client constructor upfront. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk, though one design choice regarding botUserId warrants attention - The refactoring successfully addresses the race condition by reordering initialization. The code follows existing patterns and TypeScript compilation passes. However, the deliberate choice to not update botUserId after fetching (lines 592-595) creates a potential edge case where the bot could respond to its own messages in certain configurations, though this is mitigated by the allowBots check - No files require special attention - the refactoring is straightforward <sub>Last reviewed commit: 3882589</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs