diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js
index fb7991f16226..31db5249a3f5 100644
--- a/src/structures/Webhook.js
+++ b/src/structures/Webhook.js
@@ -105,6 +105,8 @@ class Webhook {
* @property {MessageAttachment[]} [attachments] Attachments to send with the message
* @property {MessageActionRow[]|MessageActionRowOptions[]} [components]
* Action rows containing interactive components for the message (buttons, select menus)
+ * @property {Snowflake} [threadId] The id of the thread this message belongs to
+ * For interaction webhooks, this property is ignored
*/
/**
@@ -235,18 +237,38 @@ class Webhook {
return this;
}
+ /**
+ * Options that can be passed into fetchMessage.
+ * @typedef {options} WebhookFetchMessageOptions
+ * @property {boolean} [cache=true] Whether to cache the message.
+ * @property {Snowflake} [threadId] The id of the thread this message belongs to.
+ * For interaction webhooks, this property is ignored
+ */
+
/**
* Gets a message that was sent by this webhook.
* @param {Snowflake|'@original'} message The id of the message to fetch
- * @param {boolean} [cache=true] Whether to cache the message
+ * @param {WebhookFetchMessageOptions|boolean} [cacheOrOptions={}] The options to provide to fetch the message.
+ * A **deprecated** boolean may be passed instead to specify 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) {
+ async fetchMessage(message, cacheOrOptions = { cache: true }) {
+ if (typeof cacheOrOptions === 'boolean') {
+ cacheOrOptions = { cache: cacheOrOptions };
+ }
+
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
- 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;
+ const data = await this.client.api
+ .webhooks(this.id, this.token)
+ .messages(message)
+ .get({
+ query: {
+ thread_id: cacheOrOptions.threadId,
+ },
+ });
+ return this.client.channels?.cache.get(data.channel_id)?.messages._add(data, cacheOrOptions.cache) ?? data;
}
/**
@@ -269,7 +291,13 @@ class Webhook {
const d = await this.client.api
.webhooks(this.id, this.token)
.messages(typeof message === 'string' ? message : message.id)
- .patch({ data, files });
+ .patch({
+ data,
+ files,
+ query: {
+ thread_id: messagePayload.options.threadId,
+ },
+ });
const messageManager = this.client.channels?.cache.get(d.channel_id)?.messages;
if (!messageManager) return d;
@@ -294,15 +322,20 @@ class Webhook {
/**
* Delete a message that was sent by this webhook.
* @param {MessageResolvable|'@original'} message The message to delete
+ * @param {Snowflake} [threadId] The id of the thread this message belongs to
* @returns {Promise}
*/
- async deleteMessage(message) {
+ async deleteMessage(message, threadId) {
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
await this.client.api
.webhooks(this.id, this.token)
.messages(typeof message === 'string' ? message : message.id)
- .delete();
+ .delete({
+ query: {
+ thread_id: threadId,
+ },
+ });
}
/**
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 61251c5fa5ba..3601e14f09ee 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -2119,7 +2119,11 @@ export class WebhookClient extends WebhookMixin(BaseClient) {
message: MessageResolvable,
options: string | MessagePayload | WebhookEditMessageOptions,
): Promise;
+ public fetchMessage(message: Snowflake, options?: WebhookFetchMessageOptions): Promise;
+ /* tslint:disable:unified-signatures */
+ /** @deprecated */
public fetchMessage(message: Snowflake, cache?: boolean): Promise;
+ /* tslint:enable:unified-signatures */
public send(options: string | MessagePayload | WebhookMessageOptions): Promise;
}
@@ -2825,12 +2829,16 @@ export function WebhookMixin(Base?: Constructable): Constructable;
+ deleteMessage(message: MessageResolvable | APIMessage | '@original', threadId?: Snowflake): Promise;
editMessage(
message: MessageResolvable | '@original',
options: string | MessagePayload | WebhookEditMessageOptions,
): Promise;
+ fetchMessage(message: Snowflake | '@original', options?: WebhookFetchMessageOptions): Promise;
+ /* tslint:disable:unified-signatures */
+ /** @deprecated */
fetchMessage(message: Snowflake | '@original', cache?: boolean): Promise;
+ /* tslint:enable:unified-signatures */
send(options: string | MessagePayload | WebhookMessageOptions): Promise;
}
@@ -4790,9 +4798,14 @@ export interface WebhookEditData {
export type WebhookEditMessageOptions = Pick<
WebhookMessageOptions,
- 'content' | 'embeds' | 'files' | 'allowedMentions' | 'components' | 'attachments'
+ 'content' | 'embeds' | 'files' | 'allowedMentions' | 'components' | 'attachments' | 'threadId'
>;
+export interface WebhookFetchMessageOptions {
+ cache?: boolean;
+ threadId?: Snowflake;
+}
+
export interface WebhookMessageOptions extends Omit {
username?: string;
avatarURL?: string;