mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
feat(Message): replace referencedMessage with fetchReference (#5577)
This commit is contained in:
@@ -96,6 +96,7 @@ const Messages = {
|
|||||||
INVALID_ELEMENT: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,
|
INVALID_ELEMENT: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,
|
||||||
|
|
||||||
WEBHOOK_MESSAGE: 'The message was not sent by a webhook.',
|
WEBHOOK_MESSAGE: 'The message was not sent by a webhook.',
|
||||||
|
MESSAGE_REFERENCE_MISSING: 'The message does not reference another message',
|
||||||
|
|
||||||
EMOJI_TYPE: 'Emoji must be a string or GuildEmoji/ReactionEmoji',
|
EMOJI_TYPE: 'Emoji must be a string or GuildEmoji/ReactionEmoji',
|
||||||
EMOJI_MANAGED: 'Emoji is managed and has no Author.',
|
EMOJI_MANAGED: 'Emoji is managed and has no Author.',
|
||||||
|
|||||||
@@ -442,15 +442,16 @@ class Message extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Message this crosspost/reply/pin-add references, if cached
|
* Fetches the Message this crosspost/reply/pin-add references, if available to the client
|
||||||
* @type {?Message}
|
* @returns {Promise<Message>}
|
||||||
* @readonly
|
|
||||||
*/
|
*/
|
||||||
get referencedMessage() {
|
async fetchReference() {
|
||||||
if (!this.reference) return null;
|
if (!this.reference) throw new Error('MESSAGE_REFERENCE_MISSING');
|
||||||
const referenceChannel = this.client.channels.resolve(this.reference.channelID);
|
const { channelID, messageID } = this.reference;
|
||||||
if (!referenceChannel) return null;
|
const channel = this.client.channels.resolve(channelID);
|
||||||
return referenceChannel.messages.resolve(this.reference.messageID);
|
if (!channel) throw new Error('GUILD_CHANNEL_RESOLVE');
|
||||||
|
const message = await channel.messages.fetch(messageID);
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -1118,7 +1118,6 @@ declare module 'discord.js' {
|
|||||||
public webhookID: Snowflake | null;
|
public webhookID: Snowflake | null;
|
||||||
public flags: Readonly<MessageFlags>;
|
public flags: Readonly<MessageFlags>;
|
||||||
public reference: MessageReference | null;
|
public reference: MessageReference | null;
|
||||||
public readonly referencedMessage: Message | null;
|
|
||||||
public awaitReactions(
|
public awaitReactions(
|
||||||
filter: CollectorFilter<[MessageReaction, User]>,
|
filter: CollectorFilter<[MessageReaction, User]>,
|
||||||
options?: AwaitReactionsOptions,
|
options?: AwaitReactionsOptions,
|
||||||
@@ -1133,6 +1132,7 @@ declare module 'discord.js' {
|
|||||||
): Promise<Message>;
|
): Promise<Message>;
|
||||||
public edit(content: StringResolvable, options: MessageEditOptions | MessageEmbed): Promise<Message>;
|
public edit(content: StringResolvable, options: MessageEditOptions | MessageEmbed): Promise<Message>;
|
||||||
public equals(message: Message, rawData: object): boolean;
|
public equals(message: Message, rawData: object): boolean;
|
||||||
|
public fetchReference(): Promise<Message>;
|
||||||
public fetchWebhook(): Promise<Webhook>;
|
public fetchWebhook(): Promise<Webhook>;
|
||||||
public crosspost(): Promise<Message>;
|
public crosspost(): Promise<Message>;
|
||||||
public fetch(force?: boolean): Promise<Message>;
|
public fetch(force?: boolean): Promise<Message>;
|
||||||
|
|||||||
Reference in New Issue
Block a user