Skip to content

Commit

Permalink
feat(Webhook): add 'fetchMessage' method (#5530)
Browse files Browse the repository at this point in the history
  • Loading branch information
izexi committed Apr 30, 2021
1 parent d9fa180 commit 63398d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message|Object>} 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
Expand Down Expand Up @@ -326,6 +338,7 @@ class Webhook {
for (const prop of [
'send',
'sendSlackMessage',
'fetchMessage',
'edit',
'editMessage',
'delete',
Expand Down
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@ declare module 'discord.js' {
options?: WebhookEditMessageOptions,
): Promise<RawMessage>;
public editMessage(message: MessageResolvable, options: WebhookEditMessageOptions): Promise<RawMessage>;
public fetchMessage(message: Snowflake, cache?: boolean): Promise<RawMessage>;
public send(
content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions,
): Promise<RawMessage>;
Expand Down Expand Up @@ -2166,6 +2167,7 @@ declare module 'discord.js' {
options?: WebhookEditMessageOptions,
): Promise<Message | RawMessage>;
editMessage(message: MessageResolvable, options: WebhookEditMessageOptions): Promise<Message | RawMessage>;
fetchMessage(message: Snowflake, cache?: boolean): Promise<Message | RawMessage>;
send(
content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions,
): Promise<Message | RawMessage>;
Expand Down

0 comments on commit 63398d6

Please sign in to comment.