From 0e0851aa18d873925a3b41c47665a15fde440939 Mon Sep 17 00:00:00 2001 From: Jaworek Date: Fri, 25 Nov 2022 18:19:25 +0100 Subject: [PATCH] feat(InteractionResponses): add message parameter (v13) (#8838) Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Co-authored-by: Noel --- .../interfaces/InteractionResponses.js | 32 ++++++++++++------- typings/index.d.ts | 27 +++++++++------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 5bbfd855f..8d236a24e 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -114,50 +114,58 @@ class InteractionResponses { } /** - * Fetches the initial reply to this interaction. + * Fetches a reply to this interaction. * @see Webhook#fetchMessage + * @param {MessageResolvable|'@original'} [message='@original'] The response to fetch * @returns {Promise} * @example - * // Fetch the reply to this interaction + * // Fetch the initial reply to this interaction * interaction.fetchReply() * .then(reply => console.log(`Replied with ${reply.content}`)) * .catch(console.error); */ - fetchReply() { - return this.webhook.fetchMessage('@original'); + fetchReply(message = '@original') { + return this.webhook.fetchMessage(message); } /** - * Edits the initial reply to this interaction. + * Options that can be passed into {@link InteractionResponses#editReply}. + * @typedef {WebhookEditMessageOptions} InteractionEditReplyOptions + * @property {MessageResolvable|'@original'} [message='@original'] The response to edit + */ + + /** + * Edits a reply to this interaction. * @see Webhook#editMessage - * @param {string|MessagePayload|WebhookEditMessageOptions} options The new options for the message + * @param {string|MessagePayload|InteractionEditReplyOptions} options The new options for the message * @returns {Promise} * @example - * // Edit the reply to this interaction + * // Edit the initial reply to this interaction * interaction.editReply('New content') * .then(console.log) * .catch(console.error); */ async editReply(options) { if (!this.deferred && !this.replied) throw new Error('INTERACTION_NOT_REPLIED'); - const message = await this.webhook.editMessage('@original', options); + const message = await this.webhook.editMessage(options.messsage ?? '@original', options); this.replied = true; return message; } /** - * Deletes the initial reply to this interaction. + * Deletes a reply to this interaction. * @see Webhook#deleteMessage + * @param {MessageResolvable|'@original'} [message='@original'] The response to delete * @returns {Promise} * @example - * // Delete the reply to this interaction + * // Delete the initial reply to this interaction * interaction.deleteReply() * .then(console.log) * .catch(console.error); */ - async deleteReply() { + async deleteReply(message = '@original') { if (this.ephemeral) throw new Error('INTERACTION_EPHEMERAL_REPLIED'); - await this.webhook.deleteMessage('@original'); + await this.webhook.deleteMessage(message); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 1c8f35b20..43f2bd7c4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -354,11 +354,11 @@ export interface InteractionResponseFields webhook: InteractionWebhook; reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; reply(options: string | MessagePayload | InteractionReplyOptions): Promise; - deleteReply(): Promise; - editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise>; + deleteReply(message?: MessageResolvable | '@original'): Promise; + editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise>; deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; deferReply(options?: InteractionDeferReplyOptions): Promise; - fetchReply(): Promise>; + fetchReply(message?: MessageResolvable | '@original'): Promise>; followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>; } @@ -394,9 +394,9 @@ export abstract class BaseCommandInteraction; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; public deferReply(options?: InteractionDeferReplyOptions): Promise; - public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise>; - public fetchReply(): Promise>; + public deleteReply(message?: MessageResolvable | '@original'): Promise; + public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; @@ -1721,9 +1721,9 @@ export class MessageComponentInteraction e public deferReply(options?: InteractionDeferReplyOptions): Promise; public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; - public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise>; - public fetchReply(): Promise>; + public deleteReply(message?: MessageResolvable | '@original'): Promise; + public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; @@ -1954,13 +1954,13 @@ export class ModalSubmitInteraction extend public webhook: InteractionWebhook; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; - public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise>; + public deleteReply(message?: MessageResolvable | '@original'): Promise; + public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; public deferReply(options?: InteractionDeferReplyOptions): Promise; public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; - public fetchReply(): Promise>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>; public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ModalSubmitInteraction<'cached'>; @@ -6057,6 +6057,9 @@ export type WebhookEditMessageOptions = Pick< WebhookMessageOptions, 'content' | 'embeds' | 'files' | 'allowedMentions' | 'components' | 'attachments' | 'threadId' >; +export interface InteractionEditReplyOptions extends WebhookEditMessageOptions { + message?: MessageResolvable | '@original'; +} export interface WebhookFetchMessageOptions { cache?: boolean;