From 87b320f2fb48d28bff6e709b940e6ab3f2c623b1 Mon Sep 17 00:00:00 2001 From: eirk Date: Sun, 22 Aug 2021 21:49:00 -0400 Subject: [PATCH] fix pagination --- src/class/PaginationEmbed.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/class/PaginationEmbed.ts b/src/class/PaginationEmbed.ts index 3bb9bc3..b52c52d 100644 --- a/src/class/PaginationEmbed.ts +++ b/src/class/PaginationEmbed.ts @@ -3,27 +3,34 @@ import { Message, MessageEmbed, EmojiResolvable, User, MessageReaction } from 'd export default async function PaginationEmbed(message: Message, pages: MessageEmbed[], options?: {leftArrow?: EmojiResolvable, rightArrow?: EmojiResolvable, timeout?: number }) { // eslint-disable-next-line no-param-reassign options = { - leftArrow: options.leftArrow ?? '⬅️', - rightArrow: options.rightArrow ?? '➡️', - timeout: options.timeout ?? 120000, + leftArrow: options?.leftArrow ?? '⬅️', + rightArrow: options?.rightArrow ?? '➡️', + timeout: options?.timeout ?? 120000, }; - let pageNumber = 0; + let pageNumber: number = 0; const paginationMessage = await message.channel.send({ content: `Page ${pageNumber + 1} of ${pages.length}`, embeds: [pages[pageNumber]] }); await paginationMessage.react(options.leftArrow); await paginationMessage.react(options.rightArrow); - const filter = (reaction: MessageReaction, user: User) => [options.leftArrow, options.rightArrow].includes(reaction.emoji.name) && !user.bot; + const filter = (reaction: MessageReaction, user: User) => { + if ([options.leftArrow, options.rightArrow].includes(reaction.emoji.name) + && !user.bot + && user.id === message.author.id) { + return true; + } + return false; + }; const reactionCollector = paginationMessage.createReactionCollector({ filter, time: options.timeout, dispose: true, }); - reactionCollector.on('collect', (reaction) => { - reaction.users.remove(message.author); + reactionCollector.on('collect', (reaction, user) => { + reaction.users.remove(user); if (reaction.emoji.name === options.leftArrow) { if (pageNumber > 0) { pageNumber -= 1; @@ -39,6 +46,7 @@ export default async function PaginationEmbed(message: Message, pages: MessageEm } paginationMessage.edit({ content: `Page ${pageNumber + 1} / ${pages.length}`, embeds: [pages[pageNumber]] }); }); + reactionCollector.on('end', () => { if (!paginationMessage.deleted) { paginationMessage.reactions.removeAll();