mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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 <github@almeidx.dev> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -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<InteractionCallbackResponse|undefined>}
|
||||
* @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;
|
||||
|
||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -2317,9 +2317,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
||||
public update(
|
||||
options: InteractionUpdateOptions & { withResponse: true },
|
||||
): Promise<InteractionCallbackResponse<BooleanCache<Cached>>>;
|
||||
public update(options: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
|
||||
public update(options?: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
|
||||
public update(
|
||||
options: string | MessagePayload | InteractionUpdateOptions,
|
||||
options?: string | MessagePayload | InteractionUpdateOptions,
|
||||
): Promise<InteractionCallbackResponse<BooleanCache<Cached>> | undefined>;
|
||||
public launchActivity(
|
||||
options: LaunchActivityOptions & { withResponse: true },
|
||||
|
||||
@@ -1942,6 +1942,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
|
||||
expectType<Promise<Message<true>>>(interaction.fetchReply());
|
||||
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.update({ content: 'a', withResponse: true }));
|
||||
expectType<Promise<undefined>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.deferUpdate({ withResponse: true }));
|
||||
expectType<Promise<undefined>>(interaction.deferUpdate());
|
||||
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
|
||||
@@ -1970,6 +1971,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<Message<false>>>(interaction.fetchReply());
|
||||
expectType<Promise<InteractionCallbackResponse<false>>>(interaction.update({ content: 'a', withResponse: true }));
|
||||
expectType<Promise<undefined>>(interaction.update({ content: 'a', withResponse: false }));
|
||||
expectType<Promise<undefined>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse<false> | undefined>>(
|
||||
interaction.update({ content: 'a', withResponse: booleanValue }),
|
||||
);
|
||||
@@ -2004,6 +2006,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<InteractionCallbackResponse | undefined>>(
|
||||
interaction.update({ content: 'a', withResponse: booleanValue }),
|
||||
);
|
||||
expectType<Promise<undefined>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
|
||||
expectType<Promise<undefined>>(interaction.deferUpdate());
|
||||
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
|
||||
|
||||
Reference in New Issue
Block a user