Skip to content

Commit c122178

Browse files
TAEMBOkodiakhq[bot]
authored andcommitted
feat: message forwarding (#10464)
* feat: message forwarding * fix: redundant usage * feat: add additional snapshot fields * refactor: use collection to store snapshots --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 0873f9a commit c122178

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

packages/discord.js/src/structures/Message.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class Message extends Base {
364364
* @property {Snowflake} channelId The channel id that was referenced
365365
* @property {Snowflake|undefined} guildId The guild id that was referenced
366366
* @property {Snowflake|undefined} messageId The message id that was referenced
367+
* @property {MessageReferenceType} type The type of message reference
367368
*/
368369

369370
if ('message_reference' in data) {
@@ -375,6 +376,7 @@ class Message extends Base {
375376
channelId: data.message_reference.channel_id,
376377
guildId: data.message_reference.guild_id,
377378
messageId: data.message_reference.message_id,
379+
type: data.message_reference.type,
378380
};
379381
} else {
380382
this.reference ??= null;
@@ -448,6 +450,29 @@ class Message extends Base {
448450
this.poll ??= null;
449451
}
450452

453+
if (data.message_snapshots) {
454+
/**
455+
* The message associated with the message reference
456+
* @type {Collection<Snowflake, Message>}
457+
*/
458+
this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => {
459+
const channel = this.client.channels.resolve(this.reference.channelId);
460+
const snapshotData = {
461+
...snapshot.message,
462+
id: this.reference.messageId,
463+
channel_id: this.reference.channelId,
464+
guild_id: this.reference.guildId,
465+
};
466+
467+
return coll.set(
468+
this.reference.messageId,
469+
channel ? channel.messages._add(snapshotData) : new this.constructor(this.client, snapshotData),
470+
);
471+
}, new Collection());
472+
} else {
473+
this.messageSnapshots ??= new Collection();
474+
}
475+
451476
/**
452477
* A call associated with a message
453478
* @typedef {Object} MessageCall

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@
455455
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageActivityType}
456456
*/
457457

458+
/**
459+
* @external MessageReferenceType
460+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageReferenceType}
461+
*/
462+
458463
/**
459464
* @external MessageType
460465
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageType}

packages/discord.js/typings/index.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ import {
185185
InviteType,
186186
ReactionType,
187187
APIAuthorizingIntegrationOwnersMap,
188+
MessageReferenceType,
188189
} from 'discord-api-types/v10';
189190
import { ChildProcess } from 'node:child_process';
190191
import { EventEmitter } from 'node:events';
@@ -2185,6 +2186,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
21852186
public webhookId: Snowflake | null;
21862187
public flags: Readonly<MessageFlagsBitField>;
21872188
public reference: MessageReference | null;
2189+
public messageSnapshots: Collection<Snowflake, MessageSnapshot>;
21882190
public awaitMessageComponent<ComponentType extends MessageComponentType>(
21892191
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
21902192
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
@@ -6442,6 +6444,26 @@ export interface MessageMentionOptions {
64426444

64436445
export type MessageMentionTypes = 'roles' | 'users' | 'everyone';
64446446

6447+
export interface MessageSnapshot
6448+
extends Partialize<
6449+
Message,
6450+
null,
6451+
Exclude<
6452+
keyof Message,
6453+
| 'attachments'
6454+
| 'client'
6455+
| 'components'
6456+
| 'content'
6457+
| 'createdTimestamp'
6458+
| 'editedTimestamp'
6459+
| 'embeds'
6460+
| 'flags'
6461+
| 'mentions'
6462+
| 'stickers'
6463+
| 'type'
6464+
>
6465+
> {}
6466+
64456467
export interface BaseMessageOptions {
64466468
content?: string;
64476469
embeds?: readonly (JSONEncodable<APIEmbed> | APIEmbed)[];
@@ -6497,6 +6519,7 @@ export interface MessageReference {
64976519
channelId: Snowflake;
64986520
guildId: Snowflake | undefined;
64996521
messageId: Snowflake | undefined;
6522+
type: MessageReferenceType;
65006523
}
65016524

65026525
export type MessageResolvable = Message | Snowflake;

0 commit comments

Comments
 (0)