Pagination

Hello, I'm currently experiencing an issue with pagination in my Discord.js bot, specifically related to updating the content of pages. Here's a brief overview of the problem: I have implemented a pagination system that allows users to navigate through a list of items using previous and next buttons. Each page displays a limited number of items (let's say 5). The initial setup works fine, with the first page displaying the correct items. The second page displays the same objects as the first one and the third page shows the items 6-10 eventough i have 11 items so there's one item missing, which is showed when clicking on the previous page button to go back to page 2. However, when I delete an item on the last page, and the page becomes empty, the buttons for previous and next still appear, and the content of the page doesn't update accordingly. As a result, the pagination becomes inconsistent and doesn't reflect the actual state of the data. I have reviewed my code and made attempts to fix the issue, but so far, I haven't been successful. I suspect there might be a problem with updating the currentPage and totalPages variables correctly when the page becomes empty. I'm using discord.js v14.11.0 and node v18.15.0. I'll attach a video of the problem and my code down below. I would greatly appreciate any guidance or suggestions on how to resolve this issue. If there's any additional information or code that would be helpful, please let me know. Thank you in advance for your assistance!
7 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
EndergamerMC
EndergamerMCOP2y ago
EndergamerMC
EndergamerMCOP2y ago
My Code: - Command to send the list: https://srcb.in/m444uEVOSu - Event Handler for the buttons: https://srcb.in/adGxp62LoT The upper buttons should change aswell to display the index of that item to choose from the two lower buttons to do things with that item
d4
d42y ago
in the button handler, it seems like on line 67 you update currentPage but the indices from lines 50-51 weren't updated also side node, that's a bunch of duplicated code, might be helpful to create some functions and clean stuff up
EndergamerMC
EndergamerMCOP2y ago
Yeah, I wanted to get it to work first before I start cleaning it up How would I fix that problem, or how can I update the currentPage end totalPages whenever a button is clicked?
d4
d42y ago
you should just calculate the indices in line 50-51 only after you update currentPage since the indices rely on that value
EndergamerMC
EndergamerMCOP2y ago
Thank you very much! Works now
Want results from more Discord servers?
Add your server