diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 8e7ee42f79fb..642524f0b6b7 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -364,6 +364,7 @@ class Message extends Base { * @property {Snowflake} channelId The channel id that was referenced * @property {Snowflake|undefined} guildId The guild id that was referenced * @property {Snowflake|undefined} messageId The message id that was referenced + * @property {MessageReferenceType} type The type of message reference */ if ('message_reference' in data) { @@ -375,6 +376,7 @@ class Message extends Base { channelId: data.message_reference.channel_id, guildId: data.message_reference.guild_id, messageId: data.message_reference.message_id, + type: data.message_reference.type, }; } else { this.reference ??= null; @@ -448,6 +450,29 @@ class Message extends Base { this.poll ??= null; } + if (data.message_snapshots) { + /** + * The message associated with the message reference + * @type {Collection} + */ + this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => { + const channel = this.client.channels.resolve(this.reference.channelId); + const snapshotData = { + ...snapshot.message, + id: this.reference.messageId, + channel_id: this.reference.channelId, + guild_id: this.reference.guildId, + }; + + return coll.set( + this.reference.messageId, + channel ? channel.messages._add(snapshotData) : new this.constructor(this.client, snapshotData), + ); + }, new Collection()); + } else { + this.messageSnapshots ??= new Collection(); + } + /** * A call associated with a message * @typedef {Object} MessageCall diff --git a/packages/discord.js/src/util/APITypes.js b/packages/discord.js/src/util/APITypes.js index 89e3827eeb95..42b2ddae0943 100644 --- a/packages/discord.js/src/util/APITypes.js +++ b/packages/discord.js/src/util/APITypes.js @@ -455,6 +455,11 @@ * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageActivityType} */ +/** + * @external MessageReferenceType + * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageReferenceType} + */ + /** * @external MessageType * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageType} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 25eaab5839ed..f29e646f7c94 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -185,6 +185,7 @@ import { InviteType, ReactionType, APIAuthorizingIntegrationOwnersMap, + MessageReferenceType, } from 'discord-api-types/v10'; import { ChildProcess } from 'node:child_process'; import { EventEmitter } from 'node:events'; @@ -2185,6 +2186,7 @@ export class Message extends Base { public webhookId: Snowflake | null; public flags: Readonly; public reference: MessageReference | null; + public messageSnapshots: Collection; public awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise[ComponentType]>; @@ -6442,6 +6444,26 @@ export interface MessageMentionOptions { export type MessageMentionTypes = 'roles' | 'users' | 'everyone'; +export interface MessageSnapshot + extends Partialize< + Message, + null, + Exclude< + keyof Message, + | 'attachments' + | 'client' + | 'components' + | 'content' + | 'createdTimestamp' + | 'editedTimestamp' + | 'embeds' + | 'flags' + | 'mentions' + | 'stickers' + | 'type' + > + > {} + export interface BaseMessageOptions { content?: string; embeds?: readonly (JSONEncodable | APIEmbed)[]; @@ -6497,6 +6519,7 @@ export interface MessageReference { channelId: Snowflake; guildId: Snowflake | undefined; messageId: Snowflake | undefined; + type: MessageReferenceType; } export type MessageResolvable = Message | Snowflake;