feat(DMChannel): allow partial DMChannel without client user#11443
feat(DMChannel): allow partial DMChannel without client user#11443Qjuh wants to merge 3 commits intodiscordjs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughThis PR adds multi-recipient support to Discord.js DM channel handling to resolve an issue where interactions fail to validate the correct recipient before updating cache. Changes introduce recipient deduplication logic in Action.js, augment channel resolution in InteractionCreate.js, and refactor DMChannel to store and expose multiple recipient IDs instead of a single ID. Changes
Sequence DiagramsequenceDiagram
participant Discord API
participant Action
participant InteractionCreate
participant DMChannel
participant Cache
Discord API->>Action: Interaction with recipients array
Action->>Action: Deduplicate recipients
Action->>Action: Initialize/merge recipients
InteractionCreate->>InteractionCreate: Receive processed interaction
InteractionCreate->>InteractionCreate: Augment channel with user
InteractionCreate->>DMChannel: Create/update with recipients
DMChannel->>DMChannel: Build recipientIds array
DMChannel->>DMChannel: recipientId getter: find non-client user
DMChannel->>Cache: Store all recipient user objects
Cache-->>DMChannel: Recipients cached
DMChannel-->>InteractionCreate: Channel ready with recipients
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/discord.js/src/structures/DMChannel.js`:
- Around line 36-42: The code in DMChannel is using the nullish-assignment
operator on this.recipientIds which prevents updates after the first patch;
change the assignment in the constructor/patch logic so recipientIds is
merged/updated on every patch (e.g., in DMChannel, replace the
"this.recipientIds ??= [...new Set([...(this.recipientIds ?? []),
...data.recipients.map(recipient => recipient.id)])]" pattern with an explicit
assignment that always sets this.recipientIds = [...new
Set([...(this.recipientIds ?? []), ...data.recipients.map(recipient =>
recipient.id)])] so new recipients from later Action#getChannel patches are
included).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6b57e2a6-a18b-4dc0-a75b-5000cebee598
📒 Files selected for processing (4)
packages/discord.js/src/client/actions/Action.jspackages/discord.js/src/client/actions/InteractionCreate.jspackages/discord.js/src/structures/DMChannel.jspackages/discord.js/typings/index.d.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Tests
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-02-16T18:45:40.408Z
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11423
File: packages/discord.js/src/structures/MessagePayload.js:193-206
Timestamp: 2026-02-16T18:45:40.408Z
Learning: In discord.js MessagePayload.js, when mapping files to attachments, custom ids set via AttachmentBuilder.setId() should override the index-based id. The spread operator should come after the explicit id assignment to allow toJSON() values to take precedence.
Applied to files:
packages/discord.js/src/client/actions/Action.js
Since user installed applications can run in DMChannels not containing the client user we need to account for that in case of partial DMChannels being cached.
This PR now stores the ids of all known recipients, not only one. That way we can discern between a DMChannel between the client user and another user or a DMChannel between two non-client users.
Also properly resolves the issues fixed by #8950 and #9774 instead of just fixing the symptoms caused by us only storing one of the recipient's ids.
Fixes #11429