Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Message): replace referencedMessage with fetchReference #5577

Merged
merged 3 commits into from May 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/errors/Messages.js
Expand Up @@ -96,6 +96,7 @@ const Messages = {
INVALID_ELEMENT: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,

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_MANAGED: 'Emoji is managed and has no Author.',
Expand Down
17 changes: 9 additions & 8 deletions src/structures/Message.js
Expand Up @@ -406,15 +406,16 @@ class Message extends Base {
}

/**
* The Message this crosspost/reply/pin-add references, if cached
* @type {?Message}
* @readonly
* Fetches the Message this crosspost/reply/pin-add references, if available to the client
* @returns {Promise<Message>}
*/
get referencedMessage() {
if (!this.reference) return null;
const referenceChannel = this.client.channels.resolve(this.reference.channelID);
if (!referenceChannel) return null;
return referenceChannel.messages.resolve(this.reference.messageID);
async fetchReference() {
if (!this.reference) throw new Error('MESSAGE_REFERENCE_MISSING');
const { channelID, messageID } = this.reference;
const channel = this.client.channels.resolve(channelID);
if (!channel) throw new Error('GUILD_CHANNEL_RESOLVE');
const message = await channel.messages.fetch(messageID);
return message;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -1020,7 +1020,6 @@ declare module 'discord.js' {
public webhookID: Snowflake | null;
public flags: Readonly<MessageFlags>;
public reference: MessageReference | null;
public readonly referencedMessage: Message | null;
public awaitReactions(
filter: CollectorFilter<[MessageReaction, User]>,
options?: AwaitReactionsOptions,
Expand All @@ -1035,6 +1034,7 @@ declare module 'discord.js' {
): Promise<Message>;
public edit(content: StringResolvable, options: MessageEditOptions | MessageEmbed): Promise<Message>;
public equals(message: Message, rawData: object): boolean;
public fetchReference(): Promise<Message>;
public fetchWebhook(): Promise<Webhook>;
public crosspost(): Promise<Message>;
public fetch(force?: boolean): Promise<Message>;
Expand Down