diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index d2f0ff799947..7fcbf2ce010c 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -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'); diff --git a/packages/discord.js/src/structures/InteractionCollector.js b/packages/discord.js/src/structures/InteractionCollector.js index e0526951e74a..bd2efdcb626c 100644 --- a/packages/discord.js/src/structures/InteractionCollector.js +++ b/packages/discord.js/src/structures/InteractionCollector.js @@ -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'); - } } /** diff --git a/packages/discord.js/src/structures/InteractionResponse.js b/packages/discord.js/src/structures/InteractionResponse.js deleted file mode 100644 index 9b372e3932d6..000000000000 --- a/packages/discord.js/src/structures/InteractionResponse.js +++ /dev/null @@ -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} - */ - 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} - */ - fetch() { - return this.interaction.fetchReply(); - } - - /** - * Deletes the response. - * @returns {Promise} - */ - delete() { - return this.interaction.deleteReply(); - } - - /** - * Edits the response. - * @param {string|MessagePayload|WebhookMessageEditOptions} options The new options for the response. - * @returns {Promise} - */ - edit(options) { - return this.interaction.editReply(options); - } -} - -// eslint-disable-next-line import/order -const InteractionCollector = require('./InteractionCollector'); -module.exports = InteractionResponse; diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 4c130a091dd7..9fb192c2243d 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -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 */ /** diff --git a/packages/discord.js/src/structures/interfaces/InteractionResponses.js b/packages/discord.js/src/structures/interfaces/InteractionResponses.js index 899ef64743fd..947665232353 100644 --- a/packages/discord.js/src/structures/interfaces/InteractionResponses.js +++ b/packages/discord.js/src/structures/interfaces/InteractionResponses.js @@ -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} + * @returns {Promise} * @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. * Use the `withResponse` option to get the interaction callback response. * @param {string|MessagePayload|InteractionReplyOptions} options The options for the reply - * @returns {Promise} + * @returns {Promise} * @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} + * @returns {Promise} * @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} + * @returns {Promise} * @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; } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d838dff8a8b4..386d763356d0 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -568,7 +568,7 @@ export abstract class CommandInteraction e public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, ): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise>>; + public deferReply(options?: InteractionDeferReplyOptions): Promise; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, @@ -576,9 +576,7 @@ export abstract class CommandInteraction e public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; - public reply( - options: string | MessagePayload | InteractionReplyOptions, - ): Promise>>; + public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; public showModal( modal: | JSONEncodable @@ -602,24 +600,6 @@ export abstract class CommandInteraction e ): CommandInteractionOption; } -export class InteractionResponse { - private constructor(interaction: Interaction, id?: Snowflake); - public interaction: Interaction>; - public client: Client; - public id: Snowflake; - public get createdAt(): Date; - public get createdTimestamp(): number; - public awaitMessageComponent( - options?: AwaitMessageCollectorOptionsParams, - ): Promise[ComponentType]>; - public createMessageComponentCollector( - options?: MessageCollectorOptionsParams, - ): InteractionCollector[ComponentType]>; - public delete(): Promise; - public edit(options: string | MessagePayload | WebhookMessageEditOptions): Promise; - public fetch(): Promise; -} - export abstract class BaseGuild extends Base { protected constructor(client: Client, data: RawBaseGuildData); public get createdAt(): Date; @@ -2034,7 +2014,6 @@ export class InteractionCollector 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; @@ -2338,11 +2317,11 @@ export class MessageComponentInteraction e public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, ): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise>>; + public deferReply(options?: InteractionDeferReplyOptions): Promise; public deferUpdate( options: InteractionDeferUpdateOptions & { withResponse: true }, ): Promise; - public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; + public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, @@ -2350,13 +2329,9 @@ export class MessageComponentInteraction e public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; - public reply( - options: string | MessagePayload | InteractionReplyOptions, - ): Promise>>; + public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; public update(options: InteractionUpdateOptions & { withResponse: true }): Promise; - public update( - options: string | MessagePayload | InteractionUpdateOptions, - ): Promise>>; + public update(options: string | MessagePayload | InteractionUpdateOptions): Promise; public showModal( modal: | JSONEncodable @@ -2539,9 +2514,7 @@ export interface ModalMessageModalSubmitInteraction>; channelId: Snowflake; update(options: InteractionUpdateOptions & { withResponse: true }): Promise; - update( - options: string | MessagePayload | InteractionUpdateOptions, - ): Promise>>; + update(options: string | MessagePayload | InteractionUpdateOptions): Promise; inGuild(): this is ModalMessageModalSubmitInteraction<'raw' | 'cached'>; inCachedGuild(): this is ModalMessageModalSubmitInteraction<'cached'>; inRawGuild(): this is ModalMessageModalSubmitInteraction<'raw'>; @@ -2559,9 +2532,7 @@ export class ModalSubmitInteraction extend public replied: boolean; public readonly webhook: InteractionWebhook; public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; - public reply( - options: string | MessagePayload | InteractionReplyOptions, - ): Promise>>; + public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, @@ -2569,13 +2540,13 @@ export class ModalSubmitInteraction extend public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, ): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise>>; + public deferReply(options?: InteractionDeferReplyOptions): Promise; public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public deferUpdate( options: InteractionDeferUpdateOptions & { withResponse: true }, ): Promise; - public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; + public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ModalSubmitInteraction<'cached'>; public inRawGuild(): this is ModalSubmitInteraction<'raw'>; @@ -6195,7 +6166,6 @@ export interface InteractionCollectorOptions< maxComponents?: number; maxUsers?: number; message?: CacheTypeReducer; - interactionResponse?: InteractionResponse>; } export interface InteractionDeferReplyOptions {