refactor(Interaction): rename defer to deferReply (#6306)

This commit is contained in:
Jan
2021-08-05 18:30:13 +02:00
committed by GitHub
parent 5b4efd13c9
commit 4241febe24
5 changed files with 26 additions and 16 deletions

View File

@@ -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.',

View File

@@ -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() {}

View File

@@ -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() {}

View File

@@ -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<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;
@@ -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(

12
typings/index.d.ts vendored
View File

@@ -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>;
@@ -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>;
@@ -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;