Skip to content

Commit

Permalink
refactor!: remove class
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `InteractionResponse` has been removed. Create interaction collectors via `with_response` or fetching the reply.
  • Loading branch information
Jiralite committed Jan 4, 2025
1 parent f5d2926 commit d02f35f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 194 deletions.
1 change: 0 additions & 1 deletion packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
36 changes: 3 additions & 33 deletions packages/discord.js/src/structures/InteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand All @@ -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) ??
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

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

Expand Down Expand Up @@ -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');
}
}

/**
Expand Down
102 changes: 0 additions & 102 deletions packages/discord.js/src/structures/InteractionResponse.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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()
Expand All @@ -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({
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Loading

0 comments on commit d02f35f

Please sign in to comment.