diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index e8a3b1bea7b2..d283035b7e50 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -236,6 +236,18 @@ class Webhook { return this; } + /** + * Gets a message that was sent by this webhook. + * @param {Snowflake} message The ID of the message to fetch + * @param {boolean} [cache=true] Whether to cache the message + * @returns {Promise} Returns the raw message data if the webhook was instantiated as a + * {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned + */ + async fetchMessage(message, cache = true) { + const data = await this.client.api.webhooks(this.id, this.token).messages(message).get(); + return this.client.channels?.cache.get(data.channel_id)?.messages.add(data, cache) ?? data; + } + /** * Edits a message that was sent by this webhook. * @param {MessageResolvable} message The message to edit @@ -326,6 +338,7 @@ class Webhook { for (const prop of [ 'send', 'sendSlackMessage', + 'fetchMessage', 'edit', 'editMessage', 'delete', diff --git a/typings/index.d.ts b/typings/index.d.ts index ff0636054485..5bb02903408f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1819,6 +1819,7 @@ declare module 'discord.js' { options?: WebhookEditMessageOptions, ): Promise; public editMessage(message: MessageResolvable, options: WebhookEditMessageOptions): Promise; + public fetchMessage(message: Snowflake, cache?: boolean): Promise; public send( content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions, ): Promise; @@ -2166,6 +2167,7 @@ declare module 'discord.js' { options?: WebhookEditMessageOptions, ): Promise; editMessage(message: MessageResolvable, options: WebhookEditMessageOptions): Promise; + fetchMessage(message: Snowflake, cache?: boolean): Promise; send( content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions, ): Promise;