From ed593c91fb7b87ae8b512c6f127e12f33c9631b6 Mon Sep 17 00:00:00 2001 From: Jan <66554238+vaporox@users.noreply.github.com> Date: Wed, 26 May 2021 13:09:14 +0200 Subject: [PATCH] feat: InteractionDeferOptions (#5641) --- src/structures/CommandInteraction.js | 12 +++++++++--- typings/index.d.ts | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index f2b9cd423..08fc61857 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -61,9 +61,15 @@ class CommandInteraction extends Interaction { return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null; } + /** + * Options for deferring the reply to a {@link CommandInteraction}. + * @typedef {InteractionDeferOptions} + * @property {boolean} [ephemeral] Whether the reply should be ephemeral + */ + /** * Defers the reply to this interaction. - * @param {boolean} [ephemeral] Whether the reply should be ephemeral + * @param {InteractionDeferOptions} [options] Options for deferring the reply to this interaction * @returns {Promise} * @example * // Defer the reply to this interaction @@ -72,11 +78,11 @@ class CommandInteraction extends Interaction { * .catch(console.error) * @example * // Defer to send an ephemeral reply later - * interaction.defer(true) + * interaction.defer({ ephemeral: true }) * .then(console.log) * .catch(console.error); */ - async defer(ephemeral) { + async defer({ ephemeral } = {}) { if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); await this.client.api.interactions(this.id, this.token).callback.post({ data: { diff --git a/typings/index.d.ts b/typings/index.d.ts index b611bb0ab..7eee0eff4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -418,7 +418,7 @@ declare module 'discord.js' { public options: CommandInteractionOption[]; public replied: boolean; public webhook: WebhookClient; - public defer(ephemeral?: boolean): Promise; + public defer(options?: InteractionDeferOptions): Promise; public deleteReply(): Promise; public editReply( content: string | APIMessage | WebhookEditMessageOptions | MessageAdditions, @@ -3074,6 +3074,10 @@ declare module 'discord.js' { name: string; } + interface InteractionDeferOptions { + ephemeral?: boolean; + } + interface InteractionReplyOptions extends Omit { ephemeral?: boolean; }