mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Webhook): add 'fetchMessage' method (#5530)
This commit is contained in:
@@ -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
|
||||
@@ -326,6 +338,7 @@ class Webhook {
|
||||
for (const prop of [
|
||||
'send',
|
||||
'sendSlackMessage',
|
||||
'fetchMessage',
|
||||
'edit',
|
||||
'editMessage',
|
||||
'delete',
|
||||
|
||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -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>;
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user