Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -448,6 +450,29 @@ class Message extends Base {
this.poll ??= null;
}

if (data.message_snapshots) {
/**
* The message associated with the message reference
* @type {Collection<Snowflake, Message>}
*/
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
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
23 changes: 23 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -2185,6 +2186,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public webhookId: Snowflake | null;
public flags: Readonly<MessageFlagsBitField>;
public reference: MessageReference | null;
public messageSnapshots: Collection<Snowflake, MessageSnapshot>;
public awaitMessageComponent<ComponentType extends MessageComponentType>(
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
Expand Down Expand Up @@ -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> | APIEmbed)[];
Expand Down Expand Up @@ -6497,6 +6519,7 @@ export interface MessageReference {
channelId: Snowflake;
guildId: Snowflake | undefined;
messageId: Snowflake | undefined;
type: MessageReferenceType;
}

export type MessageResolvable = Message | Snowflake;
Expand Down