mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
feat: InteractionDeferOptions (#5641)
This commit is contained in:
@@ -61,9 +61,15 @@ class CommandInteraction extends Interaction {
|
|||||||
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
|
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.
|
* 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>}
|
* @returns {Promise<void>}
|
||||||
* @example
|
* @example
|
||||||
* // Defer the reply to this interaction
|
* // Defer the reply to this interaction
|
||||||
@@ -72,11 +78,11 @@ class CommandInteraction extends Interaction {
|
|||||||
* .catch(console.error)
|
* .catch(console.error)
|
||||||
* @example
|
* @example
|
||||||
* // Defer to send an ephemeral reply later
|
* // Defer to send an ephemeral reply later
|
||||||
* interaction.defer(true)
|
* interaction.defer({ ephemeral: true })
|
||||||
* .then(console.log)
|
* .then(console.log)
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async defer(ephemeral) {
|
async defer({ ephemeral } = {}) {
|
||||||
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
|
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
|
||||||
await this.client.api.interactions(this.id, this.token).callback.post({
|
await this.client.api.interactions(this.id, this.token).callback.post({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@@ -418,7 +418,7 @@ declare module 'discord.js' {
|
|||||||
public options: CommandInteractionOption[];
|
public options: CommandInteractionOption[];
|
||||||
public replied: boolean;
|
public replied: boolean;
|
||||||
public webhook: WebhookClient;
|
public webhook: WebhookClient;
|
||||||
public defer(ephemeral?: boolean): Promise<void>;
|
public defer(options?: InteractionDeferOptions): Promise<void>;
|
||||||
public deleteReply(): Promise<void>;
|
public deleteReply(): Promise<void>;
|
||||||
public editReply(
|
public editReply(
|
||||||
content: string | APIMessage | WebhookEditMessageOptions | MessageAdditions,
|
content: string | APIMessage | WebhookEditMessageOptions | MessageAdditions,
|
||||||
@@ -3074,6 +3074,10 @@ declare module 'discord.js' {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface InteractionDeferOptions {
|
||||||
|
ephemeral?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
|
interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user