Skip to content

Commit c1f5bb2

Browse files
colocatedalmeidxJiralite
authored
fix(InteractionResponses): Optional parameter for update() (#10797)
* 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 <[email protected]> Co-authored-by: Jiralite <[email protected]>
1 parent 8605fc8 commit c1f5bb2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

packages/discord.js/src/structures/interfaces/InteractionResponses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class InteractionResponses {
237237

238238
/**
239239
* Updates the original message of the component on which the interaction was received on.
240-
* @param {string|MessagePayload|InteractionUpdateOptions} options The options for the updated message
240+
* @param {string|MessagePayload|InteractionUpdateOptions} [options] The options for the updated message
241241
* @returns {Promise<InteractionCallbackResponse|undefined>}
242242
* @example
243243
* // Remove the components from the message
@@ -248,7 +248,7 @@ class InteractionResponses {
248248
* .then(console.log)
249249
* .catch(console.error);
250250
*/
251-
async update(options) {
251+
async update(options = {}) {
252252
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
253253

254254
let messagePayload;

packages/discord.js/typings/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,9 +2317,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
23172317
public update(
23182318
options: InteractionUpdateOptions & { withResponse: true },
23192319
): Promise<InteractionCallbackResponse<BooleanCache<Cached>>>;
2320-
public update(options: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
2320+
public update(options?: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
23212321
public update(
2322-
options: string | MessagePayload | InteractionUpdateOptions,
2322+
options?: string | MessagePayload | InteractionUpdateOptions,
23232323
): Promise<InteractionCallbackResponse<BooleanCache<Cached>> | undefined>;
23242324
public launchActivity(
23252325
options: LaunchActivityOptions & { withResponse: true },

packages/discord.js/typings/index.test-d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,7 @@ client.on('interactionCreate', async interaction => {
19421942
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
19431943
expectType<Promise<Message<true>>>(interaction.fetchReply());
19441944
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.update({ content: 'a', withResponse: true }));
1945+
expectType<Promise<undefined>>(interaction.update());
19451946
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.deferUpdate({ withResponse: true }));
19461947
expectType<Promise<undefined>>(interaction.deferUpdate());
19471948
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
@@ -1970,6 +1971,7 @@ client.on('interactionCreate', async interaction => {
19701971
expectType<Promise<Message<false>>>(interaction.fetchReply());
19711972
expectType<Promise<InteractionCallbackResponse<false>>>(interaction.update({ content: 'a', withResponse: true }));
19721973
expectType<Promise<undefined>>(interaction.update({ content: 'a', withResponse: false }));
1974+
expectType<Promise<undefined>>(interaction.update());
19731975
expectType<Promise<InteractionCallbackResponse<false> | undefined>>(
19741976
interaction.update({ content: 'a', withResponse: booleanValue }),
19751977
);
@@ -2004,6 +2006,7 @@ client.on('interactionCreate', async interaction => {
20042006
expectType<Promise<InteractionCallbackResponse | undefined>>(
20052007
interaction.update({ content: 'a', withResponse: booleanValue }),
20062008
);
2009+
expectType<Promise<undefined>>(interaction.update());
20072010
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
20082011
expectType<Promise<undefined>>(interaction.deferUpdate());
20092012
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));

0 commit comments

Comments
 (0)