Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(InteractionCollector): handle thread (and parent) deletion #7070

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/structures/InteractionCollector.js
Expand Up @@ -105,7 +105,9 @@ class InteractionCollector extends Collector {

if (this.channelId) {
this._handleChannelDeletion = this._handleChannelDeletion.bind(this);
this._handleThreadDeletion = this._handleThreadDeletion.bind(this);
this.client.on(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.on(Events.THREAD_DELETE, this._handleThreadDeletion);
}

if (this.guildId) {
Expand All @@ -120,6 +122,7 @@ class InteractionCollector extends Collector {
this.client.removeListener(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.removeListener(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.decrementMaxListeners();
});
Expand Down Expand Up @@ -212,11 +215,23 @@ class InteractionCollector extends Collector {
* @returns {void}
*/
_handleChannelDeletion(channel) {
if (channel.id === this.channelId) {
if (channel.id === this.channelId || channel.threads?.cache.has(this.channelId)) {
this.stop('channelDelete');
}
}

/**
* Handles checking if the thread has been deleted, and if so, stops the collector with the reason 'threadDelete'.
* @private
* @param {ThreadChannel} thread The thread that was deleted
* @returns {void}
*/
_handleThreadDeletion(thread) {
if (thread.id === this.channelId) {
this.stop('threadDelete');
}
}

/**
* Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
* @private
Expand Down