Skip to content

Commit

Permalink
fix(discord.js-utilities): fixed stop button crashing bots
Browse files Browse the repository at this point in the history
Regression issue caused by #484
  • Loading branch information
favna committed Oct 9, 2022
1 parent c479153 commit d5a9fc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Expand Up @@ -31,6 +31,7 @@ import type {
PaginatedMessageOptions,
PaginatedMessagePage,
PaginatedMessageSelectMenuOptionsFunction,
PaginatedMessageStopReasons,
PaginatedMessageWrongUserInteractionReplyFunction
} from './PaginatedMessageTypes';
import { actionIsButtonOrMenu, createPartitionedMessageRow, isMessageButtonInteraction, safelyReplyToInteraction } from './utils';
Expand Down Expand Up @@ -1142,9 +1143,17 @@ export class PaginatedMessage {
* Handles the `end` event from the collector.
* @param reason The reason for which the collector was ended.
*/
protected async handleEnd(_: Collection<Snowflake, ButtonInteraction | SelectMenuInteraction>, reason: string): Promise<void> {
protected async handleEnd(
_: Collection<Snowflake, ButtonInteraction | SelectMenuInteraction>,
reason: PaginatedMessageStopReasons
): Promise<void> {
// Ensure no race condition can occur where interacting with the message when the paginated message closes would otherwise result in a DiscordAPIError
if (this.response !== null && isAnyInteraction(this.response) && this.response.isMessageComponent()) {
if (
(reason === 'time' || reason === 'idle') &&
this.response !== null &&
isAnyInteraction(this.response) &&
this.response.isMessageComponent()
) {
this.response.message = await this.response.fetchReply();
}

Expand Down
Expand Up @@ -198,3 +198,15 @@ export interface SafeReplyToInteractionParameters<T extends 'edit' | 'reply' | n
messageMethod?: T;
messageMethodContent?: T extends 'reply' ? ReplyMessageOptions : MessageEditOptions;
}

export type PaginatedMessageStopReasons =
| 'time'
| 'idle'
| 'user'
| 'messageDelete'
| 'channelDelete'
| 'threadDelete'
| 'guildDelete'
| 'limit'
| 'componentLimit'
| 'userLimit';

0 comments on commit d5a9fc6

Please sign in to comment.