Skip to content

Commit

Permalink
refactor(Interaction): rename defer to deferReply (#6306)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx authored Aug 5, 2021
1 parent 5b4efd1 commit 4241feb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ const Messages = {
"or from a guild's application command manager.",
GUILD_UNCACHED_ROLE_RESOLVE: 'Cannot resolve roles from an arbitrary guild, provide an id instead',

INTERACTION_ALREADY_REPLIED: 'This interaction has already been deferred or replied to.',
INTERACTION_NOT_REPLIED: 'This interaction has not been deferred or replied to.',
INTERACTION_ALREADY_REPLIED: 'The reply to this interaction has already been sent or deferred.',
INTERACTION_NOT_REPLIED: 'The reply to this interaction has not been sent or deferred.',
INTERACTION_EPHEMERAL_REPLIED: 'Ephemeral responses cannot be fetched or deleted.',
INTERACTION_FETCH_EPHEMERAL: 'Ephemeral responses cannot be fetched.',

Expand Down
2 changes: 1 addition & 1 deletion src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CommandInteraction extends Interaction {

// These are here only for documentation purposes - they are implemented by InteractionResponses
/* eslint-disable no-empty-function */
defer() {}
deferReply() {}
reply() {}
fetchReply() {}
editReply() {}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/MessageComponentInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MessageComponentInteraction extends Interaction {

// These are here only for documentation purposes - they are implemented by InteractionResponses
/* eslint-disable no-empty-function */
defer() {}
deferReply() {}
reply() {}
fetchReply() {}
editReply() {}
Expand Down
22 changes: 16 additions & 6 deletions src/structures/interfaces/InteractionResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const MessagePayload = require('../MessagePayload');
class InteractionResponses {
/**
* Options for deferring the reply to an {@link Interaction}.
* @typedef {Object} InteractionDeferOptions
* @typedef {Object} InteractionDeferReplyOptions
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
* @property {boolean} [fetchReply] Whether to fetch the reply
*/
Expand All @@ -38,20 +38,20 @@ class InteractionResponses {

/**
* Defers the reply to this interaction.
* @param {InteractionDeferOptions} [options] Options for deferring the reply to this interaction
* @param {InteractionDeferReplyOptions} [options] Options for deferring the reply to this interaction
* @returns {Promise<Message|APIMessage|void>}
* @example
* // Defer the reply to this interaction
* interaction.defer()
* interaction.deferReply()
* .then(console.log)
* .catch(console.error)
* @example
* // Defer to send an ephemeral reply later
* interaction.defer({ ephemeral: true })
* interaction.deferReply({ ephemeral: true })
* .then(console.log)
* .catch(console.error);
*/
async defer(options = {}) {
async deferReply(options = {}) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
if (options.fetchReply && options.ephemeral) throw new Error('INTERACTION_FETCH_EPHEMERAL');
this.ephemeral = options.ephemeral ?? false;
Expand Down Expand Up @@ -228,7 +228,17 @@ class InteractionResponses {
}

static applyToClass(structure, ignore = []) {
const props = ['defer', 'reply', 'fetchReply', 'editReply', 'deleteReply', 'followUp', 'deferUpdate', 'update'];
const props = [
'deferReply',
'reply',
'fetchReply',
'editReply',
'deleteReply',
'followUp',
'deferUpdate',
'update',
];

for (const prop of props) {
if (ignore.includes(prop)) continue;
Object.defineProperty(
Expand Down
12 changes: 6 additions & 6 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ export class CommandInteraction extends Interaction {
public options: CommandInteractionOptionResolver;
public replied: boolean;
public webhook: InteractionWebhook;
public defer(options: InteractionDeferOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public defer(options?: InteractionDeferOptions): Promise<void>;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>;
public fetchReply(): Promise<Message | APIMessage>;
Expand Down Expand Up @@ -1218,8 +1218,8 @@ export class MessageComponentInteraction extends Interaction {
public message: Message | APIMessage;
public replied: boolean;
public webhook: InteractionWebhook;
public defer(options: InteractionDeferOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public defer(options?: InteractionDeferOptions): Promise<void>;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>;
public deleteReply(): Promise<void>;
Expand Down Expand Up @@ -3794,12 +3794,12 @@ export interface InteractionCollectorOptions<T extends Interaction> extends Coll
message?: Message | APIMessage;
}

export interface InteractionDeferOptions {
export interface InteractionDeferReplyOptions {
ephemeral?: boolean;
fetchReply?: boolean;
}

export type InteractionDeferUpdateOptions = Omit<InteractionDeferOptions, 'ephemeral'>;
export type InteractionDeferUpdateOptions = Omit<InteractionDeferReplyOptions, 'ephemeral'>;

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

0 comments on commit 4241feb

Please sign in to comment.