Skip to content

Commit

Permalink
fix(InteractionCollector): handle thread (and parent) deletion (#7070)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Dec 7, 2021
1 parent f028aea commit b5cd288
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit b5cd288

Please sign in to comment.