Skip to content

Commit

Permalink
feat: InteractionDeferOptions (#5641)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx committed May 26, 2021
1 parent 5f6ec22 commit ed593c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/structures/CommandInteraction.js
Expand Up @@ -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<void>}
* @example
* // Defer the reply to this interaction
Expand All @@ -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: {
Expand Down
6 changes: 5 additions & 1 deletion typings/index.d.ts
Expand Up @@ -418,7 +418,7 @@ declare module 'discord.js' {
public options: CommandInteractionOption[];
public replied: boolean;
public webhook: WebhookClient;
public defer(ephemeral?: boolean): Promise<void>;
public defer(options?: InteractionDeferOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(
content: string | APIMessage | WebhookEditMessageOptions | MessageAdditions,
Expand Down Expand Up @@ -3074,6 +3074,10 @@ declare module 'discord.js' {
name: string;
}

interface InteractionDeferOptions {
ephemeral?: boolean;
}

interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
ephemeral?: boolean;
}
Expand Down

0 comments on commit ed593c9

Please sign in to comment.