mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
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>
This commit is contained in:
@@ -364,6 +364,7 @@ class Message extends Base {
|
|||||||
* @property {Snowflake} channelId The channel id that was referenced
|
* @property {Snowflake} channelId The channel id that was referenced
|
||||||
* @property {Snowflake|undefined} guildId The guild 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 {Snowflake|undefined} messageId The message id that was referenced
|
||||||
|
* @property {MessageReferenceType} type The type of message reference
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ('message_reference' in data) {
|
if ('message_reference' in data) {
|
||||||
@@ -375,6 +376,7 @@ class Message extends Base {
|
|||||||
channelId: data.message_reference.channel_id,
|
channelId: data.message_reference.channel_id,
|
||||||
guildId: data.message_reference.guild_id,
|
guildId: data.message_reference.guild_id,
|
||||||
messageId: data.message_reference.message_id,
|
messageId: data.message_reference.message_id,
|
||||||
|
type: data.message_reference.type,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.reference ??= null;
|
this.reference ??= null;
|
||||||
@@ -448,6 +450,29 @@ class Message extends Base {
|
|||||||
this.poll ??= null;
|
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
|
* A call associated with a message
|
||||||
* @typedef {Object} MessageCall
|
* @typedef {Object} MessageCall
|
||||||
|
|||||||
@@ -455,6 +455,11 @@
|
|||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageActivityType}
|
* @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
|
* @external MessageType
|
||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageType}
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageType}
|
||||||
|
|||||||
23
packages/discord.js/typings/index.d.ts
vendored
23
packages/discord.js/typings/index.d.ts
vendored
@@ -185,6 +185,7 @@ import {
|
|||||||
InviteType,
|
InviteType,
|
||||||
ReactionType,
|
ReactionType,
|
||||||
APIAuthorizingIntegrationOwnersMap,
|
APIAuthorizingIntegrationOwnersMap,
|
||||||
|
MessageReferenceType,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import { ChildProcess } from 'node:child_process';
|
import { ChildProcess } from 'node:child_process';
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
@@ -2185,6 +2186,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
|
|||||||
public webhookId: Snowflake | null;
|
public webhookId: Snowflake | null;
|
||||||
public flags: Readonly<MessageFlagsBitField>;
|
public flags: Readonly<MessageFlagsBitField>;
|
||||||
public reference: MessageReference | null;
|
public reference: MessageReference | null;
|
||||||
|
public messageSnapshots: Collection<Snowflake, MessageSnapshot>;
|
||||||
public awaitMessageComponent<ComponentType extends MessageComponentType>(
|
public awaitMessageComponent<ComponentType extends MessageComponentType>(
|
||||||
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
|
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
|
||||||
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
|
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
|
||||||
@@ -6442,6 +6444,26 @@ export interface MessageMentionOptions {
|
|||||||
|
|
||||||
export type MessageMentionTypes = 'roles' | 'users' | 'everyone';
|
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 {
|
export interface BaseMessageOptions {
|
||||||
content?: string;
|
content?: string;
|
||||||
embeds?: readonly (JSONEncodable<APIEmbed> | APIEmbed)[];
|
embeds?: readonly (JSONEncodable<APIEmbed> | APIEmbed)[];
|
||||||
@@ -6497,6 +6519,7 @@ export interface MessageReference {
|
|||||||
channelId: Snowflake;
|
channelId: Snowflake;
|
||||||
guildId: Snowflake | undefined;
|
guildId: Snowflake | undefined;
|
||||||
messageId: Snowflake | undefined;
|
messageId: Snowflake | undefined;
|
||||||
|
type: MessageReferenceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageResolvable = Message | Snowflake;
|
export type MessageResolvable = Message | Snowflake;
|
||||||
|
|||||||
Reference in New Issue
Block a user