diff --git a/packages/discord.js/src/client/actions/Action.js b/packages/discord.js/src/client/actions/Action.js index 791fe480d0e6..0578f060b1d1 100644 --- a/packages/discord.js/src/client/actions/Action.js +++ b/packages/discord.js/src/client/actions/Action.js @@ -33,10 +33,15 @@ class Action { const payloadData = {}; const id = data.channel_id ?? data.id; - if (!('recipients' in data)) { - // Try to resolve the recipient, but do not add the client user. + if ('recipients' in data) { + // Try to resolve the recipient, but do not add if already existing in recipients. const recipient = data.author ?? data.user ?? { id: data.user_id }; - if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient]; + if (data.recipients.every(existingRecipient => recipient.id !== existingRecipient.id)) + payloadData.recipients = [...data.recipients, recipient]; + } else { + // Try to resolve the recipient. + const recipient = data.author ?? data.user ?? { id: data.user_id }; + payloadData.recipients = [recipient]; } if (id !== undefined) payloadData.id = id; diff --git a/packages/discord.js/src/client/actions/InteractionCreate.js b/packages/discord.js/src/client/actions/InteractionCreate.js index 2e263425fca2..cac5b56ef064 100644 --- a/packages/discord.js/src/client/actions/InteractionCreate.js +++ b/packages/discord.js/src/client/actions/InteractionCreate.js @@ -21,7 +21,9 @@ class InteractionCreateAction extends Action { const client = this.client; // Resolve and cache partial channels for Interaction#channel getter - const channel = data.channel && this.getChannel(data.channel); + const channel = + data.channel && + this.getChannel({ ...data.channel, ...('recipients' in data.channel ? { user: data.user } : undefined) }); // Do not emit this for interactions that cache messages that are non-text-based. let InteractionClass; diff --git a/packages/discord.js/src/structures/DMChannel.js b/packages/discord.js/src/structures/DMChannel.js index c7e7db9864d3..252171d665b6 100644 --- a/packages/discord.js/src/structures/DMChannel.js +++ b/packages/discord.js/src/structures/DMChannel.js @@ -32,17 +32,19 @@ class DMChannel extends BaseChannel { super._patch(data); if (data.recipients) { - const recipient = data.recipients[0]; - /** - * The recipient's id + * The recipients' ids * - * @type {Snowflake} + * @type {Snowflake[]} */ - this.recipientId = recipient.id; - - if ('username' in recipient || this.client.options.partials.includes(Partials.User)) { - this.client.users._add(recipient); + this.recipientIds = [ + ...new Set([...(this.recipientIds ?? []), ...data.recipients.map(recipient => recipient.id)]), + ]; + + for (const recipient of data.recipients) { + if ('username' in recipient || this.client.options.partials.includes(Partials.User)) { + this.client.users._add(recipient); + } } } @@ -78,7 +80,21 @@ class DMChannel extends BaseChannel { } /** - * The recipient on the other end of the DM + * The recipient's id, if this is a DMChannel with the client user. + * + * @type {?Snowflake} + * @readonly + */ + get recipientId() { + if (this.recipientIds.includes(this.client.user.id)) { + return this.recipientIds.find(recipientId => recipientId !== this.client.user.id) ?? null; + } + + return null; + } + + /** + * The recipient on the other end of the DM, if this is a DMChannel with the client user. * * @type {?User} * @readonly diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 6b7d67197f73..e754488eb51d 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1292,7 +1292,8 @@ export interface DMChannel export class DMChannel extends BaseChannel { private constructor(client: Client, data?: RawDMChannelData); public flags: Readonly; - public recipientId: Snowflake; + public get recipientId(): Snowflake | null; + public recipientIds: Snowflake[]; public get recipient(): User | null; public type: ChannelType.DM; public fetch(force?: boolean): Promise;