message with back and forward buttons
i've seen bots that have buttons to go back and forward and they change the buttons and embed based on if u go back or forward. if the bot shuts down i'm not sure what would happen if u tried to go back/forward. is there a way to make the pagination work after the bot is restarted?
14 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i'm overall confused how a system like this works
buttons being clicked will create ButtonInteractions regardless of whether the bot has been restarted or not
they would just need to be handled in a way that wouldn't be cleared by a restart
which is to say, you'd handle them in the
interactionCreate
event, rather than a temporary collectorOne method would be to have a
page number
in the footer of the embed which can be read by the bot to determine which page should be displayed when the next
or back
button is clickedbut when the bot is restarted how could the bot figure out what the current page is?
Because the current page number would be in the footer of the embed as I mentioned. You're essentially just persistently logging the page number in the embed itself
ahh i see
but when u go back in the embed the previous color of a button won't stay?
like u won't have information if a button was disabled before
i mean access the prev data for that
so lets say i have an embed with 2 buttons. When i press a button the color changes to green. lets say i press go to page 2. new buttons will appear and i will not have the green button. when the bot restarts and then i press go back to page 1 how will i get the information weather or not the button on page one turned green
but i can't get the previous button
like when u go to page 2 it completely changes the buttons
so lets say this is page 1. and then this is page 2. how will i be able to figure out what buttons were selected when the page is requested to go back to one and the bot restarted
like the value of the disabled property is what i am trying to access but the page one version of that
i understand. Like lets say someone presses UTC button on page 1. the color will change to blue. then u can go to page 2 and come back to page one and the utc button will still be blue
but when the bot is restarted there is no way to persist the data from page one and to indicate what u pressed before the bot restarted.
that's why question how can u persist that
That's smart
But for other commands that have a back button u would need to just store in custom id cuz that would take lots of space in db
If someone spams the command
What's the limit on custom id length and can u just put Json in the id?
How not really? Basically every slash command interaction will be stored in db
If you're having such a hard time creating a paginated embed yourself, I'm pretty sure there are NPM packages that do this already. Might save yourself the headache by using an existing module
npm
discordjs-button-embed-pagination
Discord.js V14 embed pagination with button. Latest version: 5.0.0, last published: 25 days ago. Start using discordjs-button-embed-pagination in your project by running
npm i discordjs-button-embed-pagination
. There are no other projects in the npm registry using discordjs-button-embed-pagination.Yeah that package won't remember previous state of select menus and stuff
Can custom id have any char
Iirc, yes