Skip to content

feat(DMChannel): allow partial DMChannel without client user#11443

Open
Qjuh wants to merge 3 commits intodiscordjs:mainfrom
Qjuh:feat/dmchannel-without-client
Open

feat(DMChannel): allow partial DMChannel without client user#11443
Qjuh wants to merge 3 commits intodiscordjs:mainfrom
Qjuh:feat/dmchannel-without-client

Conversation

@Qjuh
Copy link
Member

@Qjuh Qjuh commented Mar 6, 2026

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

@Qjuh Qjuh requested a review from a team as a code owner March 6, 2026 11:01
@vercel
Copy link

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Mar 10, 2026 1:10pm
discord-js-guide Skipped Skipped Mar 10, 2026 1:10pm

Request Review

@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 6, 2026 11:01 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js March 6, 2026 11:01 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 10, 2026 12:38 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js March 10, 2026 12:38 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
DM Channel Multi-Recipient Support
packages/discord.js/src/structures/DMChannel.js, packages/discord.js/typings/index.d.ts
Replaced single-recipient handling with multi-recipient support. Added public recipientIds: Snowflake[] property and converted recipientId from property to getter that returns the other party's ID when client user is in recipientIds. Iterates all recipients for cache population instead of only the first.
Recipient Data Processing
packages/discord.js/src/client/actions/Action.js, packages/discord.js/src/client/actions/InteractionCreate.js
Added deduplication logic for recipients in payload data, explicitly initializing recipients array when absent. InteractionCreate now augments channel data with user field when recipients exist before channel resolution.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: allowing DMChannel to exist without the client user, which is the core change enabling multi-recipient support.
Description check ✅ Passed The description clearly explains the motivation and approach: storing all recipient IDs instead of one, enabling distinction between DMChannels with/without the client user, and fixing underlying issues.
Linked Issues check ✅ Passed Changes properly address issue #11429 by storing all recipient IDs in DMChannel, enabling correct identification of which DM channel includes the client user vs. non-client users.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the multi-recipient DMChannel support: Action.js handles recipient deduplication, InteractionCreate.js resolves channel data with recipients, DMChannel.js implements recipientIds array and recipientId getter, and typings reflect the new API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3942a6 and aa2a39f.

📒 Files selected for processing (4)
  • packages/discord.js/src/client/actions/Action.js
  • packages/discord.js/src/client/actions/InteractionCreate.js
  • packages/discord.js/src/structures/DMChannel.js
  • packages/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

@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 10, 2026 13:10 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js March 10, 2026 13:10 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Interactions fail to check if DMs are with another user before updating cache

1 participant