From 4241febe24e6b552083b3d0ee1a086409b900714 Mon Sep 17 00:00:00 2001 From: Jan <66554238+vaporox@users.noreply.github.com> Date: Thu, 5 Aug 2021 18:30:13 +0200 Subject: [PATCH] refactor(Interaction): rename defer to deferReply (#6306) --- src/errors/Messages.js | 4 ++-- src/structures/CommandInteraction.js | 2 +- src/structures/MessageComponentInteraction.js | 2 +- .../interfaces/InteractionResponses.js | 22 ++++++++++++++----- typings/index.d.ts | 12 +++++----- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 770f89d7d..c97aa4cf8 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -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.', diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 09bfa975e..b7a33ac20 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -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() {} diff --git a/src/structures/MessageComponentInteraction.js b/src/structures/MessageComponentInteraction.js index 65c7f2730..5ac774b75 100644 --- a/src/structures/MessageComponentInteraction.js +++ b/src/structures/MessageComponentInteraction.js @@ -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() {} diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 0586fc346..c692a55ca 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -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 */ @@ -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} * @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; @@ -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( diff --git a/typings/index.d.ts b/typings/index.d.ts index d99ccad2b..bd9fd5ff6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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; - public defer(options?: InteractionDeferOptions): Promise; + public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; + public deferReply(options?: InteractionDeferReplyOptions): Promise; public deleteReply(): Promise; public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; public fetchReply(): Promise; @@ -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; - public defer(options?: InteractionDeferOptions): Promise; + public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; + public deferReply(options?: InteractionDeferReplyOptions): Promise; public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; public deleteReply(): Promise; @@ -3794,12 +3794,12 @@ export interface InteractionCollectorOptions extends Coll message?: Message | APIMessage; } -export interface InteractionDeferOptions { +export interface InteractionDeferReplyOptions { ephemeral?: boolean; fetchReply?: boolean; } -export type InteractionDeferUpdateOptions = Omit; +export type InteractionDeferUpdateOptions = Omit; export interface InteractionReplyOptions extends Omit { ephemeral?: boolean;