From fbda4fe5256802abf3ae4d74e5df8961e7950603 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 25 May 2025 13:01:35 +0100 Subject: [PATCH] fix(InteractionResponses): Optional parameter for update() (#10797) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🔧 don't error out if no options are provided This commit stops calls to `options.withResponse`, etc erroring out when `interaction.update();` is called alone with no params. * tweak: ⚙️ make options optional on typedef * fix: 🔧 update index.d.ts Update types to allow options to be optional * types: add tests --------- Co-authored-by: Almeida Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- .../src/structures/interfaces/InteractionResponses.js | 6 +++--- packages/discord.js/typings/index.d.ts | 2 +- packages/discord.js/typings/index.test-d.ts | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 8db178652..4a96fd0ba 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -320,8 +320,8 @@ class InteractionResponses { /** * Updates the original message of the component on which the interaction was received on. - * @param {string|MessagePayload|InteractionUpdateOptions} options The options for the updated message - * @returns {Promise} + * @param {string|MessagePayload|InteractionUpdateOptions} [options] The options for the updated message + * @returns {Promise} * @example * // Remove the components from the message * interaction.update({ @@ -331,7 +331,7 @@ class InteractionResponses { * .then(console.log) * .catch(console.error); */ - async update(options) { + async update(options = {}) { if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied); if (typeof options !== 'string' && 'fetchReply' in options) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 60e0a94ee..88cf807a2 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2677,7 +2677,7 @@ export class MessageComponentInteraction e /** @deprecated `fetchReply` is deprecated. Use `withResponse` instead or fetch the response after using the method. */ public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise>>; public update( - options: string | MessagePayload | InteractionUpdateOptions, + options?: string | MessagePayload | InteractionUpdateOptions, ): Promise>>; public launchActivity( options: LaunchActivityOptions & { withResponse: true }, diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index a01a8b0cb..e8196d542 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -1953,6 +1953,7 @@ client.on('interactionCreate', async interaction => { expectType>>(interaction.update({ content: 'a', fetchReply: true })); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.update({ content: 'a', withResponse: true })); + expectType>>(interaction.update()); expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>>(interaction.followUp({ content: 'a' })); expectType>>(interaction.launchActivity({ withResponse: true })); @@ -1974,6 +1975,7 @@ client.on('interactionCreate', async interaction => { expectType>>(interaction.update({ content: 'a', fetchReply: true })); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.update({ content: 'a', withResponse: true })); + expectType>>(interaction.update()); expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>>(interaction.followUp({ content: 'a' })); expectType>>(interaction.launchActivity({ withResponse: true })); @@ -1995,6 +1997,7 @@ client.on('interactionCreate', async interaction => { expectType>(interaction.update({ content: 'a', fetchReply: true })); expectType>(interaction.deferUpdate({ fetchReply: true })); expectType>(interaction.update({ content: 'a', withResponse: true })); + expectType>(interaction.update()); expectType>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.followUp({ content: 'a' })); expectType>(interaction.launchActivity({ withResponse: true }));