List Pagination Session
A ListPaginationSession is a special type of pagination session made to paginate a list of items.
Initially, the item's values are received at the session's constructor. You can also include a refreshing system in the session to refresh the items with their newest state, if desired.
Creation
Creation
Extend the AbstractListPaginationSession class:
import { } from '@nyx-discord/plugin-sessions/djs';
class extends <number> {}The first type argument is the type of the items, and the second is the session's return type.
In updatePage() you can now use getCurrentPageItems(), which is an utility method that calculates and returns the current page's items.
Implementation
Implement it the same way you'd implement a PaginationSession.
Initialization
Instantiate and start your session the same way as a regular one, but passing the list of items:
const = new ({
,
,
,
: [1, 2, 3, /** ... */]
});
await .();Example
This example will paginate a list of the currently cached guilds:
import type { } from '@nyx-discord/djs';
import {
,
type ,
type
} from '@nyx-discord/plugin-sessions/djs';
import { , , , type } from 'discord.js';
class extends <, void> {
constructor(: {
: ;
: string;
: ;
: [];
}) {
super();
}
public async () {
const = this.();
const = this.();
await this..({
: [, ],
: .,
});
}
protected async (: ): <boolean> {
const = this.();
const = this.();
if ('update' in ) {
await .({
: [, ],
: .,
});
}
return true;
}
public async () {
const = this.();
await this..({
: [],
: .,
});
}
protected (): {
const = this.();
const = new ()
.(() => .('# Guilds'));
for (const of ) {
const = .();
if () {
.(() =>
.(() => .(.))
.(() => .())
);
} else {
.(() => .(.));
}
}
return ;
}
}You can then use it in your command or anywhere where you have an interaction:
const = new ({ , , , });
await .();