Skip to content

fix(discord): handle DMs via raw gateway events#87

Open
claylevering wants to merge 1 commit into
nanocoai:mainfrom
claylevering:fix/discord-dm-raw-gateway
Open

fix(discord): handle DMs via raw gateway events#87
claylevering wants to merge 1 commit into
nanocoai:mainfrom
claylevering:fix/discord-dm-raw-gateway

Conversation

@claylevering
Copy link
Copy Markdown

Summary

  • discord.js v14 does not reliably emit messageCreate for DMs even with Partials.Channel and Partials.Message enabled
  • The raw gateway MESSAGE_CREATE event fires correctly for DMs, so DMs are now processed directly from the raw event
  • Guild messages continue through the standard messageCreate handler (unaffected)

What changed

  • Added Partials.Channel and Partials.Message to Client options
  • Added raw gateway listener that processes DM MESSAGE_CREATE events (no guild_id)
  • messageCreate handler now skips DMs (if (!message.guild) return) to avoid double-processing
  • Updated test: DM test case uses new triggerRawDM helper instead of triggerMessage
  • Added Partials to discord.js test mock

How it was found

Confirmed on a live bot running discord.js 14.26.2:

  1. Raw gateway events arrive for DMs (packet.t === 'MESSAGE_CREATE' with no guild_id)
  2. messageCreate never fires for DMs, even with Partials enabled
  3. Guild messages work fine through messageCreate

Test plan

  • All 34 existing tests pass
  • DM test updated to exercise the raw event path
  • Verified on live bot: DMs received and processed, guild messages unaffected

🤖 Generated with Claude Code

discord.js v14 does not reliably emit messageCreate for DMs even with
Partials.Channel and Partials.Message enabled. The raw gateway event
fires correctly, so DMs are now processed directly from the raw event
while guild messages continue through the standard messageCreate handler.

- Add Partials.Channel and Partials.Message to Client options
- Add raw gateway listener for DM MESSAGE_CREATE events
- Skip DMs in messageCreate handler (handled by raw listener)
- Update DM test to use triggerRawDM helper
- Add Partials to discord.js test mock

Tested with discord.js 14.26.2 on a live bot — confirmed raw events
arrive for DMs while messageCreate does not.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant