refactor!: Remove InteractionResponse (#10689)

BREAKING CHANGE: `InteractionResponse` has been removed. Create interaction collectors via `with_response` or fetching the reply.
This commit is contained in:
Jiralite
2025-01-12 21:48:08 +00:00
committed by GitHub
parent f70ab41d56
commit 7e81d3b6c8
7 changed files with 118 additions and 188 deletions

View File

@@ -148,7 +148,6 @@ exports.InteractionCallbackResource = require('./structures/InteractionCallbackR
exports.InteractionCallbackResponse = require('./structures/InteractionCallbackResponse');
exports.BaseInteraction = require('./structures/BaseInteraction');
exports.InteractionCollector = require('./structures/InteractionCollector');
exports.InteractionResponse = require('./structures/InteractionResponse');
exports.InteractionWebhook = require('./structures/InteractionWebhook');
exports.Invite = require('./structures/Invite');
exports.InviteGuild = require('./structures/InviteGuild');

View File

@@ -14,8 +14,6 @@ const Events = require('../util/Events');
* @property {number} [maxComponents] The maximum number of components to collect
* @property {number} [maxUsers] The maximum number of users to interact
* @property {Message|APIMessage} [message] The message to listen to interactions from
* @property {InteractionResponse} [interactionResponse] The interaction response to listen
* to message component interactions from
*/
/**
@@ -40,30 +38,20 @@ class InteractionCollector extends Collector {
* The message from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.messageId = options.message?.id ?? options.interactionResponse?.interaction.message?.id ?? null;
/**
* The message interaction id from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.messageInteractionId = options.interactionResponse?.id ?? null;
this.messageId = options.message?.id ?? null;
/**
* The channel from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.channelId =
options.interactionResponse?.interaction.channelId ??
options.message?.channelId ??
options.message?.channel_id ??
this.client.channels.resolveId(options.channel);
options.message?.channelId ?? options.message?.channel_id ?? this.client.channels.resolveId(options.channel);
/**
* The guild from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.guildId =
options.interactionResponse?.interaction.guildId ??
options.message?.guildId ??
options.message?.guild_id ??
this.client.guilds.resolveId(options.channel?.guild) ??
@@ -99,7 +87,7 @@ class InteractionCollector extends Collector {
if (messages.has(this.messageId)) this.stop('messageDelete');
};
if (this.messageId || this.messageInteractionId) {
if (this.messageId) {
this._handleMessageDeletion = this._handleMessageDeletion.bind(this);
this.client.on(Events.MessageDelete, this._handleMessageDeletion);
this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
@@ -151,13 +139,6 @@ class InteractionCollector extends Collector {
if (this.interactionType && interaction.type !== this.interactionType) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
if (this.messageId && interaction.message?.id !== this.messageId) return null;
if (
this.messageInteractionId &&
interaction.message?.interactionMetadata?.id &&
interaction.message.interactionMetadata.id !== this.messageInteractionId
) {
return null;
}
if (this.channelId && interaction.channelId !== this.channelId) return null;
if (this.guildId && interaction.guildId !== this.guildId) return null;
@@ -178,13 +159,6 @@ class InteractionCollector extends Collector {
if (this.type && interaction.type !== this.type) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
if (this.messageId && interaction.message?.id !== this.messageId) return null;
if (
this.messageInteractionId &&
interaction.message?.interactionMetadata?.id &&
interaction.message.interactionMetadata.id !== this.messageInteractionId
) {
return null;
}
if (this.channelId && interaction.channelId !== this.channelId) return null;
if (this.guildId && interaction.guildId !== this.guildId) return null;
@@ -223,10 +197,6 @@ class InteractionCollector extends Collector {
if (message.id === this.messageId) {
this.stop('messageDelete');
}
if (message.interactionMetadata?.id === this.messageInteractionId) {
this.stop('messageDelete');
}
}
/**

View File

@@ -1,102 +0,0 @@
'use strict';
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { InteractionType } = require('discord-api-types/v10');
const { DiscordjsError, ErrorCodes } = require('../errors');
/**
* Represents an interaction's response
*/
class InteractionResponse {
constructor(interaction, id) {
/**
* The interaction associated with the interaction response
* @type {BaseInteraction}
*/
this.interaction = interaction;
/**
* The id of the original interaction response
* @type {Snowflake}
*/
this.id = id ?? interaction.id;
this.client = interaction.client;
}
/**
* The timestamp the interaction response was created at
* @type {number}
* @readonly
*/
get createdTimestamp() {
return DiscordSnowflake.timestampFrom(this.id);
}
/**
* The time the interaction response was created at
* @type {Date}
* @readonly
*/
get createdAt() {
return new Date(this.createdTimestamp);
}
/**
* Collects a single component interaction that passes the filter.
* The Promise will reject if the time expires.
* @param {AwaitMessageComponentOptions} [options={}] Options to pass to the internal collector
* @returns {Promise<MessageComponentInteraction>}
*/
awaitMessageComponent(options = {}) {
const _options = { ...options, max: 1 };
return new Promise((resolve, reject) => {
const collector = this.createMessageComponentCollector(_options);
collector.once('end', (interactions, reason) => {
const interaction = interactions.first();
if (interaction) resolve(interaction);
else reject(new DiscordjsError(ErrorCodes.InteractionCollectorError, reason));
});
});
}
/**
* Creates a message component interaction collector
* @param {MessageComponentCollectorOptions} [options={}] Options to send to the collector
* @returns {InteractionCollector}
*/
createMessageComponentCollector(options = {}) {
return new InteractionCollector(this.client, {
...options,
interactionResponse: this,
interactionType: InteractionType.MessageComponent,
});
}
/**
* Fetches the response as a {@link Message} object.
* @returns {Promise<Message>}
*/
fetch() {
return this.interaction.fetchReply();
}
/**
* Deletes the response.
* @returns {Promise<void>}
*/
delete() {
return this.interaction.deleteReply();
}
/**
* Edits the response.
* @param {string|MessagePayload|WebhookMessageEditOptions} options The new options for the response.
* @returns {Promise<Message>}
*/
edit(options) {
return this.interaction.editReply(options);
}
}
// eslint-disable-next-line import/order
const InteractionCollector = require('./InteractionCollector');
module.exports = InteractionResponse;

View File

@@ -644,7 +644,6 @@ class Message extends Base {
* @property {ComponentType} [componentType] The type of component interaction to collect
* @property {number} [idle] Time to wait without another message component interaction before ending the collector
* @property {boolean} [dispose] Whether to remove the message component interaction after collecting
* @property {InteractionResponse} [interactionResponse] The interaction response to collect interactions from
*/
/**

View File

@@ -7,7 +7,6 @@ const { DiscordjsError, ErrorCodes } = require('../../errors');
const MessageFlagsBitField = require('../../util/MessageFlagsBitField');
const InteractionCallbackResponse = require('../InteractionCallbackResponse');
const InteractionCollector = require('../InteractionCollector');
const InteractionResponse = require('../InteractionResponse');
const MessagePayload = require('../MessagePayload');
/**
@@ -61,7 +60,7 @@ class InteractionResponses {
/**
* Defers the reply to this interaction.
* @param {InteractionDeferReplyOptions} [options] Options for deferring the reply to this interaction
* @returns {Promise<InteractionResponse|InteractionCallbackResponse>}
* @returns {Promise<InteractionCallbackResponse|undefined>}
* @example
* // Defer the reply to this interaction
* interaction.deferReply()
@@ -92,16 +91,14 @@ class InteractionResponses {
this.deferred = true;
this.ephemeral = resolvedFlags.has(MessageFlags.Ephemeral);
return options.withResponse
? new InteractionCallbackResponse(this.client, response)
: new InteractionResponse(this);
return options.withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
}
/**
* Creates a reply to this interaction.
* <info>Use the `withResponse` option to get the interaction callback response.</info>
* @param {string|MessagePayload|InteractionReplyOptions} options The options for the reply
* @returns {Promise<InteractionResponse|InteractionCallbackResponse>}
* @returns {Promise<InteractionCallbackResponse|undefined>}
* @example
* // Reply to the interaction and fetch the response
* interaction.reply({ content: 'Pong!', withResponse: true })
@@ -137,9 +134,7 @@ class InteractionResponses {
this.ephemeral = Boolean(data.flags & MessageFlags.Ephemeral);
this.replied = true;
return options.withResponse
? new InteractionCallbackResponse(this.client, response)
: new InteractionResponse(this);
return options.withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
}
/**
@@ -211,7 +206,7 @@ class InteractionResponses {
/**
* Defers an update to the message to which the component was attached.
* @param {InteractionDeferUpdateOptions} [options] Options for deferring the update to this interaction
* @returns {Promise<InteractionResponse|InteractionCallbackResponse>}
* @returns {Promise<InteractionCallbackResponse|undefined>}
* @example
* // Defer updating and reset the component's loading state
* interaction.deferUpdate()
@@ -229,15 +224,13 @@ class InteractionResponses {
});
this.deferred = true;
return options.withResponse
? new InteractionCallbackResponse(this.client, response)
: new InteractionResponse(this, this.message?.interactionMetadata?.id);
return options.withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
}
/**
* Updates the original message of the component on which the interaction was received on.
* @param {string|MessagePayload|InteractionUpdateOptions} options The options for the updated message
* @returns {Promise<InteractionResponse|InteractionCallbackResponse>}
* @returns {Promise<InteractionCallbackResponse|undefined>}
* @example
* // Remove the components from the message
* interaction.update({
@@ -267,9 +260,7 @@ class InteractionResponses {
});
this.replied = true;
return options.withResponse
? new InteractionCallbackResponse(this.client, response)
: new InteractionResponse(this, this.message.interactionMetadata?.id);
return options.withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
}
/**

View File

@@ -568,7 +568,8 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
public deferReply(
options: InteractionDeferReplyOptions & { withResponse: true },
): Promise<InteractionCallbackResponse>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise<undefined>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionCallbackResponse | undefined>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | InteractionEditReplyOptions,
@@ -576,9 +577,10 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public reply(options: InteractionReplyOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public reply(options: InteractionReplyOptions & { withResponse: false }): Promise<undefined>;
public reply(
options: string | MessagePayload | InteractionReplyOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
): Promise<InteractionCallbackResponse | undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
@@ -591,8 +593,15 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
| JSONEncodable<APIModalInteractionResponseCallbackData>
| ModalComponentData
| APIModalInteractionResponseCallbackData,
options?: ShowModalOptions,
options?: ShowModalOptions & { withResponse: false },
): Promise<undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
| ModalComponentData
| APIModalInteractionResponseCallbackData,
options?: ShowModalOptions,
): Promise<InteractionCallbackResponse | undefined>;
public awaitModalSubmit(
options: AwaitModalSubmitOptions<ModalSubmitInteraction>,
): Promise<ModalSubmitInteraction<Cached>>;
@@ -602,24 +611,6 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
): CommandInteractionOption<Cached>;
}
export class InteractionResponse<Cached extends boolean = boolean> {
private constructor(interaction: Interaction, id?: Snowflake);
public interaction: Interaction<WrapBooleanCache<Cached>>;
public client: Client;
public id: Snowflake;
public get createdAt(): Date;
public get createdTimestamp(): number;
public awaitMessageComponent<ComponentType extends MessageComponentType>(
options?: AwaitMessageCollectorOptionsParams<ComponentType, Cached>,
): Promise<MappedInteractionTypes<Cached>[ComponentType]>;
public createMessageComponentCollector<ComponentType extends MessageComponentType>(
options?: MessageCollectorOptionsParams<ComponentType, Cached>,
): InteractionCollector<MappedInteractionTypes<Cached>[ComponentType]>;
public delete(): Promise<void>;
public edit(options: string | MessagePayload | WebhookMessageEditOptions): Promise<Message>;
public fetch(): Promise<Message>;
}
export abstract class BaseGuild extends Base {
protected constructor(client: Client<true>, data: RawBaseGuildData);
public get createdAt(): Date;
@@ -2033,7 +2024,6 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
private _handleGuildDeletion(guild: Guild): void;
public channelId: Snowflake | null;
public messageInteractionId: Snowflake | null;
public componentType: ComponentType | null;
public guildId: Snowflake | null;
public interactionType: InteractionType | null;
@@ -2337,11 +2327,13 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public deferReply(
options: InteractionDeferReplyOptions & { withResponse: true },
): Promise<InteractionCallbackResponse>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise<undefined>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionCallbackResponse | undefined>;
public deferUpdate(
options: InteractionDeferUpdateOptions & { withResponse: true },
): Promise<InteractionCallbackResponse>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deferUpdate(options?: InteractionDeferUpdateOptions & { withResponse: false }): Promise<undefined>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionCallbackResponse | undefined>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | InteractionEditReplyOptions,
@@ -2349,13 +2341,15 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public reply(options: InteractionReplyOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public reply(options: InteractionReplyOptions & { withResponse: false }): Promise<undefined>;
public reply(
options: string | MessagePayload | InteractionReplyOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
): Promise<InteractionCallbackResponse | undefined>;
public update(options: InteractionUpdateOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public update(options: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
public update(
options: string | MessagePayload | InteractionUpdateOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
): Promise<InteractionCallbackResponse | undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
@@ -2368,8 +2362,15 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
| JSONEncodable<APIModalInteractionResponseCallbackData>
| ModalComponentData
| APIModalInteractionResponseCallbackData,
options?: ShowModalOptions,
options?: ShowModalOptions & { withResponse: false },
): Promise<undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
| ModalComponentData
| APIModalInteractionResponseCallbackData,
options?: ShowModalOptions,
): Promise<InteractionCallbackResponse | undefined>;
public awaitModalSubmit(
options: AwaitModalSubmitOptions<ModalSubmitInteraction>,
): Promise<ModalSubmitInteraction<Cached>>;
@@ -2538,9 +2539,8 @@ export interface ModalMessageModalSubmitInteraction<Cached extends CacheType = C
message: Message<BooleanCache<Cached>>;
channelId: Snowflake;
update(options: InteractionUpdateOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
update(
options: string | MessagePayload | InteractionUpdateOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
update(options: InteractionUpdateOptions & { withResponse: false }): Promise<undefined>;
update(options: string | MessagePayload | InteractionUpdateOptions): Promise<InteractionCallbackResponse | undefined>;
inGuild(): this is ModalMessageModalSubmitInteraction<'raw' | 'cached'>;
inCachedGuild(): this is ModalMessageModalSubmitInteraction<'cached'>;
inRawGuild(): this is ModalMessageModalSubmitInteraction<'raw'>;
@@ -2558,9 +2558,10 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
public replied: boolean;
public readonly webhook: InteractionWebhook;
public reply(options: InteractionReplyOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public reply(options: InteractionReplyOptions & { withResponse: false }): Promise<undefined>;
public reply(
options: string | MessagePayload | InteractionReplyOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
): Promise<InteractionCallbackResponse | undefined>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | InteractionEditReplyOptions,
@@ -2568,13 +2569,15 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
public deferReply(
options: InteractionDeferReplyOptions & { withResponse: true },
): Promise<InteractionCallbackResponse>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise<undefined>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionCallbackResponse | undefined>;
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public deferUpdate(
options: InteractionDeferUpdateOptions & { withResponse: true },
): Promise<InteractionCallbackResponse>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deferUpdate(options?: InteractionDeferUpdateOptions & { withResponse: false }): Promise<undefined>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionCallbackResponse | undefined>;
public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ModalSubmitInteraction<'cached'>;
public inRawGuild(): this is ModalSubmitInteraction<'raw'>;
@@ -6213,7 +6216,6 @@ export interface InteractionCollectorOptions<
maxComponents?: number;
maxUsers?: number;
message?: CacheTypeReducer<Cached, Message, APIMessage>;
interactionResponse?: InteractionResponse<BooleanCache<Cached>>;
}
export interface InteractionDeferReplyOptions {

View File

@@ -1791,10 +1791,20 @@ client.on('interactionCreate', async interaction => {
expectType<Guild>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<true>>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
} else if (interaction.inRawGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
@@ -1803,10 +1813,24 @@ client.on('interactionCreate', async interaction => {
expectType<null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message<false>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<false>>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<undefined>>(interaction.update({ content: 'a', withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.update({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
} else if (interaction.inGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
@@ -1815,10 +1839,24 @@ client.on('interactionCreate', async interaction => {
expectType<Guild | null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<undefined>>(interaction.update({ content: 'a', withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.update({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
}
}
@@ -1854,6 +1892,15 @@ client.on('interactionCreate', async interaction => {
expectAssignable<CommandInteraction<'cached'>>(interaction);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<true>>>(interaction.fetchReply());
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
@@ -1862,6 +1909,15 @@ client.on('interactionCreate', async interaction => {
expectType<null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message<false>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<false>>>(interaction.fetchReply());
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
@@ -1870,6 +1926,15 @@ client.on('interactionCreate', async interaction => {
expectType<Guild | null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<undefined>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<undefined>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.reply({ content: 'a', withResponse: booleanValue }),
);
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.deferReply({ withResponse: booleanValue }),
);
expectType<Promise<Message>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message>>(interaction.fetchReply());
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
@@ -2063,27 +2128,33 @@ client.on('interactionCreate', async interaction => {
expectType<Guild>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<true>>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
} else if (interaction.inRawGuild()) {
expectAssignable<ModalSubmitInteraction>(interaction);
expectType<null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<Message<false>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<false>>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
} else if (interaction.inGuild()) {
expectAssignable<ModalSubmitInteraction>(interaction);
expectType<Guild | null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferReply());
expectType<Promise<Message>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message>>(interaction.fetchReply());
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<undefined>>(interaction.deferUpdate());
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
}
}