From c1f5bb2fba099ab3b21656b35f700f54f0f10acc 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 | 4 ++-- packages/discord.js/typings/index.d.ts | 4 ++-- 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 c32b82bf0..80244c678 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -237,7 +237,7 @@ 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 + * @param {string|MessagePayload|InteractionUpdateOptions} [options] The options for the updated message * @returns {Promise} * @example * // Remove the components from the message @@ -248,7 +248,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); let messagePayload; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 0eb807c07..e95359290 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2317,9 +2317,9 @@ export class MessageComponentInteraction e public update( options: InteractionUpdateOptions & { withResponse: true }, ): Promise>>; - public update(options: InteractionUpdateOptions & { withResponse: false }): Promise; + public update(options?: InteractionUpdateOptions & { withResponse: false }): Promise; public update( - options: string | MessagePayload | InteractionUpdateOptions, + options?: string | MessagePayload | InteractionUpdateOptions, ): Promise> | undefined>; 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 eacfcfdaa..102732c3d 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -1942,6 +1942,7 @@ client.on('interactionCreate', async interaction => { expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.update({ content: 'a', withResponse: true })); + expectType>(interaction.update()); expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>>(interaction.followUp({ content: 'a' })); @@ -1970,6 +1971,7 @@ client.on('interactionCreate', async interaction => { expectType>>(interaction.fetchReply()); expectType>>(interaction.update({ content: 'a', withResponse: true })); expectType>(interaction.update({ content: 'a', withResponse: false })); + expectType>(interaction.update()); expectType | undefined>>( interaction.update({ content: 'a', withResponse: booleanValue }), ); @@ -2004,6 +2006,7 @@ client.on('interactionCreate', async interaction => { expectType>( interaction.update({ content: 'a', withResponse: booleanValue }), ); + expectType>(interaction.update()); expectType>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>(interaction.followUp({ content: 'a' }));