Pagination Session
A PaginationSession is a special type of session made to be paginated (have pages).
From a manager's perspective, a pagination session is just a regular session. The pagination logic happens inside the session itself.
Page switch
A page switch is triggered when the user sends an interaction to the pagination session, and a page can be extracted from it:
- It attempts to extract a referred page, depending on the interaction type:
- Buttons: Extracts from the customId.
- Select Menu: Extracts from the customId. If no page is present there, and it's a
StringSelectMenu, and only one value was selected, it extracts from the selected value. - Modal: Extracts from the customId. If no page is present there, it iterates through the modal's components, searching for a component whose
customIdis the session'scustomId. If there is one, the page is extracted from said component's value.
- If there's no referred page, it behaves like a regular session, passing the interaction to the appropiate handler.
- If there's a referred page, it updates its
currentPageand calls#updatePage().
Overriding page resolving
You can override this behavior by overriding extractPageFromInteraction(), or the more concrete methods:
extractPageFromButton()for buttonsextractPageFromSelectMenu()for select menusextractPageFromModal()for modals
Creation
Creation
Extend the AbstractPaginationSession class:
import { } from '@nyx-discord/plugin-sessions/djs';
class extends {}Implementation
Apart from the base Session implementation, also implement the updatePage() method:
import { , type } from '@nyx-discord/plugin-sessions/djs';
protected async (: ): <boolean> {
if ('update' in ) {
await .({ : `Page: ${this.}` });
}
return true;
}
}Similarly to update(), it must return whether the session's TTL should be renewed or not.
Initialization
Instantiate and start your session the same way as a regular one:
const = new ({ , : , : });
await .();Pagination customId
The page to switch to is usually extracted from the customId. This means you'll need to change the way you build it in case you want to make a component that switches to a specific page.
Page switch row
The AbstractPaginationSession has a utility method for building an action row containing two buttons that switch to the previous and next page:
const = this.();
await this..({ : [] });
This row uses emoji arrows to avoid issues with localized text.
