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.", "or from a guild's application command manager.",
GUILD_UNCACHED_ROLE_RESOLVE: 'Cannot resolve roles from an arbitrary guild, provide an id instead', 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_ALREADY_REPLIED: 'The reply to this interaction has already been sent or deferred.',
INTERACTION_NOT_REPLIED: 'This interaction has not been deferred or replied to.', 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_EPHEMERAL_REPLIED: 'Ephemeral responses cannot be fetched or deleted.',
INTERACTION_FETCH_EPHEMERAL: 'Ephemeral responses cannot be fetched.', 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 // These are here only for documentation purposes - they are implemented by InteractionResponses
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
defer() {} deferReply() {}
reply() {} reply() {}
fetchReply() {} fetchReply() {}
editReply() {} editReply() {}

View File

@@ -89,7 +89,7 @@ class MessageComponentInteraction extends Interaction {
// These are here only for documentation purposes - they are implemented by InteractionResponses // These are here only for documentation purposes - they are implemented by InteractionResponses
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
defer() {} deferReply() {}
reply() {} reply() {}
fetchReply() {} fetchReply() {}
editReply() {} editReply() {}

View File

@@ -12,7 +12,7 @@ const MessagePayload = require('../MessagePayload');
class InteractionResponses { class InteractionResponses {
/** /**
* Options for deferring the reply to an {@link Interaction}. * 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} [ephemeral] Whether the reply should be ephemeral
* @property {boolean} [fetchReply] Whether to fetch the reply * @property {boolean} [fetchReply] Whether to fetch the reply
*/ */
@@ -38,20 +38,20 @@ class InteractionResponses {
/** /**
* Defers the reply to this interaction. * 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>} * @returns {Promise<Message|APIMessage|void>}
* @example * @example
* // Defer the reply to this interaction * // Defer the reply to this interaction
* interaction.defer() * interaction.deferReply()
* .then(console.log) * .then(console.log)
* .catch(console.error) * .catch(console.error)
* @example * @example
* // Defer to send an ephemeral reply later * // Defer to send an ephemeral reply later
* interaction.defer({ ephemeral: true }) * interaction.deferReply({ ephemeral: true })
* .then(console.log) * .then(console.log)
* .catch(console.error); * .catch(console.error);
*/ */
async defer(options = {}) { async deferReply(options = {}) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
if (options.fetchReply && options.ephemeral) throw new Error('INTERACTION_FETCH_EPHEMERAL'); if (options.fetchReply && options.ephemeral) throw new Error('INTERACTION_FETCH_EPHEMERAL');
this.ephemeral = options.ephemeral ?? false; this.ephemeral = options.ephemeral ?? false;
@@ -228,7 +228,17 @@ class InteractionResponses {
} }
static applyToClass(structure, ignore = []) { 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) { for (const prop of props) {
if (ignore.includes(prop)) continue; if (ignore.includes(prop)) continue;
Object.defineProperty( Object.defineProperty(

12
typings/index.d.ts vendored
View File

@@ -505,8 +505,8 @@ export class CommandInteraction extends Interaction {
public options: CommandInteractionOptionResolver; public options: CommandInteractionOptionResolver;
public replied: boolean; public replied: boolean;
public webhook: InteractionWebhook; public webhook: InteractionWebhook;
public defer(options: InteractionDeferOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public defer(options?: InteractionDeferOptions): Promise<void>; public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deleteReply(): Promise<void>; public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>; public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>;
public fetchReply(): Promise<Message | APIMessage>; public fetchReply(): Promise<Message | APIMessage>;
@@ -1218,8 +1218,8 @@ export class MessageComponentInteraction extends Interaction {
public message: Message | APIMessage; public message: Message | APIMessage;
public replied: boolean; public replied: boolean;
public webhook: InteractionWebhook; public webhook: InteractionWebhook;
public defer(options: InteractionDeferOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public defer(options?: InteractionDeferOptions): Promise<void>; public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>;
public deleteReply(): Promise<void>; public deleteReply(): Promise<void>;
@@ -3794,12 +3794,12 @@ export interface InteractionCollectorOptions<T extends Interaction> extends Coll
message?: Message | APIMessage; message?: Message | APIMessage;
} }
export interface InteractionDeferOptions { export interface InteractionDeferReplyOptions {
ephemeral?: boolean; ephemeral?: boolean;
fetchReply?: boolean; fetchReply?: boolean;
} }
export type InteractionDeferUpdateOptions = Omit<InteractionDeferOptions, 'ephemeral'>; export type InteractionDeferUpdateOptions = Omit<InteractionDeferReplyOptions, 'ephemeral'>;
export interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> { export interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
ephemeral?: boolean; ephemeral?: boolean;