From 77bbffbab0180d04345552018b81dd00d408929d Mon Sep 17 00:00:00 2001 From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:51:17 -0400 Subject: [PATCH 1/9] feat(InteractionResponses): add message parameter --- .../src/structures/interfaces/InteractionResponses.js | 11 ++++++----- packages/discord.js/typings/index.d.ts | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index f8f32ebe607d..0e7fdbc8c435 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -136,21 +136,22 @@ class InteractionResponses { } /** - * Edits the initial reply to this interaction. + * Edits a reply to this interaction. * @see Webhook#editMessage * @param {string|MessagePayload|WebhookEditMessageOptions} options The new options for the message + * @param {MessageResolvable|"@original"} [message="@original"] The response to edit * @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) { + async editReply(options, message = '@original') { if (!this.deferred && !this.replied) throw new DiscordjsError(ErrorCodes.InteractionNotReplied); - const message = await this.webhook.editMessage('@original', options); + const msg = await this.webhook.editMessage(message, options); this.replied = true; - return message; + return msg; } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index e2586331a58d..d7016f1196ce 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -442,6 +442,7 @@ export abstract class CommandInteraction e public deleteReply(): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, + message?: MessageResolvable | '@original', ): Promise>>; public fetchReply(): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; @@ -1832,6 +1833,7 @@ export class MessageComponentInteraction e public deleteReply(): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, + message?: MessageResolvable | '@original', ): Promise>>; public fetchReply(): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; @@ -2022,6 +2024,7 @@ export class ModalSubmitInteraction extend public deleteReply(): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, + message?: MessageResolvable | '@original', ): Promise>>; public deferReply( options: InteractionDeferReplyOptions & { fetchReply: true }, From bea93ef0f8546df084aa43bf680c6314932ddd0c Mon Sep 17 00:00:00 2001 From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com> Date: Thu, 20 Oct 2022 20:55:55 -0400 Subject: [PATCH 2/9] chore: apply to other methods and use single quote --- .../structures/interfaces/InteractionResponses.js | 12 +++++++----- packages/discord.js/typings/index.d.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 0e7fdbc8c435..27df01fadc97 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -124,6 +124,7 @@ class InteractionResponses { /** * Fetches the initial 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 @@ -131,15 +132,15 @@ class InteractionResponses { * .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 a reply to this interaction. * @see Webhook#editMessage * @param {string|MessagePayload|WebhookEditMessageOptions} options The new options for the message - * @param {MessageResolvable|"@original"} [message="@original"] The response to edit + * @param {MessageResolvable|'@original'} [message='@original'] The response to edit * @returns {Promise} * @example * // Edit the initial reply to this interaction @@ -157,6 +158,7 @@ class InteractionResponses { /** * Deletes the initial reply to this interaction. * @see Webhook#deleteMessage + * @param {MessageResolvable|'@original'} [message='@original'] The response to edit * @returns {Promise} * @example * // Delete the reply to this interaction @@ -164,9 +166,9 @@ class InteractionResponses { * .then(console.log) * .catch(console.error); */ - async deleteReply() { + async deleteReply(message = '@original') { if (this.ephemeral) throw new DiscordjsError(ErrorCodes.InteractionEphemeralReplied); - await this.webhook.deleteMessage('@original'); + await this.webhook.deleteMessage(message); } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d7016f1196ce..cf0b768f6748 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -439,12 +439,12 @@ export abstract class CommandInteraction e options: InteractionDeferReplyOptions & { fetchReply: true }, ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions): Promise>>; - public deleteReply(): Promise; + public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, message?: MessageResolvable | '@original', ): Promise>>; - public fetchReply(): Promise>>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( @@ -1830,12 +1830,12 @@ export class MessageComponentInteraction e options: InteractionDeferUpdateOptions & { fetchReply: true }, ): Promise>>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; - public deleteReply(): Promise; + public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, message?: MessageResolvable | '@original', ): Promise>>; - public fetchReply(): Promise>>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( @@ -2021,7 +2021,7 @@ export class ModalSubmitInteraction extend public reply( options: string | MessagePayload | InteractionReplyOptions, ): Promise>>; - public deleteReply(): Promise; + public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | WebhookEditMessageOptions, message?: MessageResolvable | '@original', @@ -2030,7 +2030,7 @@ export class ModalSubmitInteraction extend options: InteractionDeferReplyOptions & { fetchReply: true }, ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions): Promise>>; - public fetchReply(): Promise>>; + public fetchReply(message?: MessageResolvable | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public deferUpdate( options: InteractionDeferUpdateOptions & { fetchReply: true }, From 23d5ce1ea85f899fa0634efe9657cfea1b7eb76d Mon Sep 17 00:00:00 2001 From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com> Date: Thu, 20 Oct 2022 20:58:24 -0400 Subject: [PATCH 3/9] docs: better method description --- .../src/structures/interfaces/InteractionResponses.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 27df01fadc97..a5766a7e31a0 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -122,12 +122,12 @@ 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); @@ -156,12 +156,12 @@ class InteractionResponses { } /** - * Deletes the initial reply to this interaction. + * Deletes a reply to this interaction. * @see Webhook#deleteMessage * @param {MessageResolvable|'@original'} [message='@original'] The response to edit * @returns {Promise} * @example - * // Delete the reply to this interaction + * // Delete the initial reply to this interaction * interaction.deleteReply() * .then(console.log) * .catch(console.error); From 5bb4936ca851907e9f4ed1f28560a7f613755c15 Mon Sep 17 00:00:00 2001 From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Date: Fri, 21 Oct 2022 07:04:30 -0400 Subject: [PATCH 4/9] docs: edit vs delete --- .../src/structures/interfaces/InteractionResponses.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index a5766a7e31a0..4e7b349789fb 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -158,7 +158,7 @@ class InteractionResponses { /** * Deletes a reply to this interaction. * @see Webhook#deleteMessage - * @param {MessageResolvable|'@original'} [message='@original'] The response to edit + * @param {MessageResolvable|'@original'} [message='@original'] The response to delete * @returns {Promise} * @example * // Delete the initial reply to this interaction From 7ffe8832941898b9b3ba7e461d98d431fb7e18b9 Mon Sep 17 00:00:00 2001 From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com> Date: Sun, 23 Oct 2022 21:51:34 -0400 Subject: [PATCH 5/9] chore: merge message parameter with options --- .../structures/interfaces/InteractionResponses.js | 10 +++++++--- packages/discord.js/typings/index.d.ts | 13 +++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 4e7b349789fb..85354333c209 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -136,11 +136,15 @@ class InteractionResponses { return this.webhook.fetchMessage(message); } + /** + * @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 {MessageResolvable|'@original'} [message='@original'] The response to edit + * @param {string|MessagePayload|InteractionEditReplyOptions} options The new options for the message * @returns {Promise} * @example * // Edit the initial reply to this interaction @@ -148,7 +152,7 @@ class InteractionResponses { * .then(console.log) * .catch(console.error); */ - async editReply(options, message = '@original') { + async editReply({ message = '@original', ...options }) { if (!this.deferred && !this.replied) throw new DiscordjsError(ErrorCodes.InteractionNotReplied); const msg = await this.webhook.editMessage(message, options); this.replied = true; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index cf0b768f6748..eec7496507e1 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -441,8 +441,7 @@ export abstract class CommandInteraction e public deferReply(options?: InteractionDeferReplyOptions): Promise>>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( - options: string | MessagePayload | WebhookEditMessageOptions, - message?: MessageResolvable | '@original', + options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public fetchReply(message?: MessageResolvable | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; @@ -1832,8 +1831,7 @@ export class MessageComponentInteraction e public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( - options: string | MessagePayload | WebhookEditMessageOptions, - message?: MessageResolvable | '@original', + options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public fetchReply(message?: MessageResolvable | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; @@ -2023,8 +2021,7 @@ export class ModalSubmitInteraction extend ): Promise>>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( - options: string | MessagePayload | WebhookEditMessageOptions, - message?: MessageResolvable | '@original', + options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public deferReply( options: InteractionDeferReplyOptions & { fetchReply: true }, @@ -5758,6 +5755,10 @@ export interface WebhookEditMessageOptions extends Omit Date: Tue, 25 Oct 2022 21:09:36 -0400 Subject: [PATCH 6/9] fix: allow parameter to be a string --- .../src/structures/interfaces/InteractionResponses.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 85354333c209..3f01c9fcb52f 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -138,7 +138,7 @@ class InteractionResponses { /** * @typedef {WebhookEditMessageOptions} InteractionEditReplyOptions - * @property {MessageResolvable|'@original'} [message='@original'] The response to edit + * @property {MessageResolvable|'@original'} [message] The response to edit */ /** @@ -152,9 +152,9 @@ class InteractionResponses { * .then(console.log) * .catch(console.error); */ - async editReply({ message = '@original', ...options }) { + async editReply(options) { if (!this.deferred && !this.replied) throw new DiscordjsError(ErrorCodes.InteractionNotReplied); - const msg = await this.webhook.editMessage(message, options); + const msg = await this.webhook.editMessage(options.message ?? '@original', options); this.replied = true; return msg; } From 6858aec50535feddd45a607e1c377ef6a261ac4f Mon Sep 17 00:00:00 2001 From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Date: Tue, 25 Oct 2022 22:12:31 -0400 Subject: [PATCH 7/9] docs: show default value --- .../src/structures/interfaces/InteractionResponses.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 3f01c9fcb52f..69aa977ef052 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -138,7 +138,7 @@ class InteractionResponses { /** * @typedef {WebhookEditMessageOptions} InteractionEditReplyOptions - * @property {MessageResolvable|'@original'} [message] The response to edit + * @property {MessageResolvable|'@original'} [message='@original'] The response to edit */ /** From fc3be31edf0b24eac116377b3cb879153d6aedb8 Mon Sep 17 00:00:00 2001 From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Date: Thu, 27 Oct 2022 07:13:19 -0400 Subject: [PATCH 8/9] types: change fetchReply parameter to Snowflake --- .../src/structures/interfaces/InteractionResponses.js | 2 +- packages/discord.js/typings/index.d.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 69aa977ef052..81760df56ab1 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -124,7 +124,7 @@ class InteractionResponses { /** * Fetches a reply to this interaction. * @see Webhook#fetchMessage - * @param {MessageResolvable|'@original'} [message='@original'] The response to fetch + * @param {Snowflake|'@original'} [message='@original'] The response to fetch * @returns {Promise} * @example * // Fetch the initial reply to this interaction diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index eec7496507e1..f5fb2acbdca8 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -443,7 +443,7 @@ export abstract class CommandInteraction e public editReply( options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; - public fetchReply(message?: MessageResolvable | '@original'): Promise>>; + public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( @@ -1833,7 +1833,7 @@ export class MessageComponentInteraction e public editReply( options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; - public fetchReply(message?: MessageResolvable | '@original'): Promise>>; + public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( @@ -2027,7 +2027,7 @@ export class ModalSubmitInteraction extend options: InteractionDeferReplyOptions & { fetchReply: true }, ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions): Promise>>; - public fetchReply(message?: MessageResolvable | '@original'): Promise>>; + public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public deferUpdate( options: InteractionDeferUpdateOptions & { fetchReply: true }, From 08577839ad7e19d17c97d8502d90df17c69d1dc0 Mon Sep 17 00:00:00 2001 From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Date: Sun, 30 Oct 2022 07:08:19 -0400 Subject: [PATCH 9/9] fix: allow deleting ephemeral reply --- .../discord.js/src/structures/interfaces/InteractionResponses.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 81760df56ab1..5d07325756b0 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -171,7 +171,6 @@ class InteractionResponses { * .catch(console.error); */ async deleteReply(message = '@original') { - if (this.ephemeral) throw new DiscordjsError(ErrorCodes.InteractionEphemeralReplied); await this.webhook.deleteMessage(message); }