mirror of
https://github.com/discordjs/discord.js.git
synced 2026-09-17 08:47:27 +00: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:
@@ -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<InteractionCallbackResponse|Message|void>}
|
||||
* @param {string|MessagePayload|InteractionUpdateOptions} [options] The options for the updated message
|
||||
* @returns {Promise<InteractionCallbackResponse|Message|InteractionResponse>}
|
||||
* @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) {
|
||||
|
||||
+1
-1
@@ -2677,7 +2677,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
||||
/** @deprecated `fetchReply` is deprecated. Use `withResponse` instead or fetch the response after using the method. */
|
||||
public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<Message<BooleanCache<Cached>>>;
|
||||
public update(
|
||||
options: string | MessagePayload | InteractionUpdateOptions,
|
||||
options?: string | MessagePayload | InteractionUpdateOptions,
|
||||
): Promise<InteractionResponse<BooleanCache<Cached>>>;
|
||||
public launchActivity(
|
||||
options: LaunchActivityOptions & { withResponse: true },
|
||||
|
||||
@@ -1953,6 +1953,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<Message<true>>>(interaction.update({ content: 'a', fetchReply: true }));
|
||||
expectType<Promise<Message<true>>>(interaction.deferUpdate({ fetchReply: true }));
|
||||
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.update({ content: 'a', withResponse: true }));
|
||||
expectType<Promise<InteractionResponse<true>>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.deferUpdate({ withResponse: true }));
|
||||
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
|
||||
expectType<Promise<InteractionCallbackResponse<true>>>(interaction.launchActivity({ withResponse: true }));
|
||||
@@ -1974,6 +1975,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<Message<false>>>(interaction.update({ content: 'a', fetchReply: true }));
|
||||
expectType<Promise<Message<false>>>(interaction.deferUpdate({ fetchReply: true }));
|
||||
expectType<Promise<InteractionCallbackResponse<false>>>(interaction.update({ content: 'a', withResponse: true }));
|
||||
expectType<Promise<InteractionResponse<false>>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse<false>>>(interaction.deferUpdate({ withResponse: true }));
|
||||
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
|
||||
expectType<Promise<InteractionCallbackResponse<false>>>(interaction.launchActivity({ withResponse: true }));
|
||||
@@ -1995,6 +1997,7 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<Promise<Message>>(interaction.update({ content: 'a', fetchReply: true }));
|
||||
expectType<Promise<Message>>(interaction.deferUpdate({ fetchReply: true }));
|
||||
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
|
||||
expectType<Promise<InteractionResponse>>(interaction.update());
|
||||
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
|
||||
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
|
||||
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
|
||||
|
||||
Reference in New Issue
Block a user