Skip to content

Commit

Permalink
fix(utilities): race condition issue for closed paginated message (#484)
Browse files Browse the repository at this point in the history
* fix(utilities): race condition issue for closed paginated message

This commit fixes a bug where the button components won't get removed
due to a race condition error:
`DiscordAPIError: Interaction has already been acknowledged.`.
This occurs when trying to interact with the message when it is about to
close the paginated message.

Co-authored-by: Jeroen Claassens <support@favware.tech>
  • Loading branch information
goestav and favna committed Oct 8, 2022
1 parent fe9315d commit 8c9c9b7
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -1142,7 +1142,12 @@ export class PaginatedMessage {
* Handles the `end` event from the collector.
* @param reason The reason for which the collector was ended.
*/
protected handleEnd(_: Collection<Snowflake, ButtonInteraction | SelectMenuInteraction>, reason: string): void {
protected async handleEnd(_: Collection<Snowflake, ButtonInteraction | SelectMenuInteraction>, reason: string): 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()) {
this.response.message = await this.response.fetchReply();
}

// Remove all listeners from the collector:
this.collector?.removeAllListeners();

Expand Down

0 comments on commit 8c9c9b7

Please sign in to comment.