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(Webhook): add 'fetchMessage' method #5530

Merged
merged 2 commits into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ class Webhook {
return this;
}

/**
* Gets a message that was sent by this webhook.
* @param {Snowflake} message The ID of the message to fetch
izexi marked this conversation as resolved.
Show resolved Hide resolved
* @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 @@ -316,6 +328,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 @@ -1815,6 +1815,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 @@ -2162,6 +2163,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