Class Pagination

The pagination class.

Hierarchy

Constructors

  • Example

    const pagination = new Pagination(interaction, {
    firstEmoji: "⏮",
    prevEmoji: "◀️",
    nextEmoji: "▶️",
    lastEmoji: "⏭",
    limit: 5,
    idle: 5 * 60 * 1000,
    ephemeral: false,
    prevDescription: "",
    postDescription: "",
    attachments: [],
    buttonStyle: "SECONDARY",
    loop: false,
    });

    Parameters

    • messageOrInteraction: ChatInputCommandInteraction<"cached"> | MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached"> | AnySelectMenuInteraction<"cached"> | ButtonInteraction<"cached"> | ModalSubmitInteraction<"cached"> | Message<boolean>

      The message or interaction to reply with the pagination message

    • options: Partial<Options> = {}

      The pagination options

    Returns Pagination

Properties

actionRows: ActionRowBuilder<MessageActionRowComponentBuilder>[]

The action rows of the final message.

attachments: (BufferResolvable | Stream | JSONEncodable<APIAttachment> | Attachment | AttachmentBuilder | AttachmentPayload)[]

The attachments to show with the paginated messages.

Default Value

[]

authorizedUsers: string[]

All the authorized users who can use the pagination buttons

buttonInfo: ButtonsOptions

Pagination button infos.

Default Value

defaultOptions.buttonInfo

buttons: Record<string, PButtonBuilder>

The pagination buttons.

collector?: InteractionCollector<ButtonInteraction<"cached">> | InteractionCollector<ButtonInteraction<CacheType>>

The collector of the pagination.

currentPage: number

The current page number.

data: APIEmbed

The API data associated with this embed.

descriptions: string[]

The descriptions to paginate through.

embeds: (APIEmbed | JSONEncodable<APIEmbed>)[]

The embeds if paginating through embeds.

Default Value

[]

ephemeral: boolean

Whether the reply should be ephemeral or not.

Default Value

false

fieldPaginate: boolean

Whether if paginating through embed's fields.

Default Value

false

idle: number

The idle time before closing.

Default Value

5 * 60 * 1_000

images: string[]

The images to paginate through.

interaction: ChatInputCommandInteraction<"cached"> | MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached"> | AnySelectMenuInteraction<"cached"> | ButtonInteraction<"cached"> | ModalSubmitInteraction<"cached"> | Message<boolean>

The interaction that the paginator is for.

limit: number

The limit of entries per page.

Default Value

5

loop: boolean

Whether to loop through the pages or not.

Default Value

false

postDescription: string

The description to show after the paginated descriptions.

Default Value

""

prevDescription: string

The description to show before the paginated descriptions.

Default Value

""

totalEntry: number

The total number of entries.

totalPages: number

The total number of pages.

Methods

  • Adds a custom action row below or above the pagination button action row.

    Example

    const pagination = new Pagination(interaction)
    .addActionRows([new ActionRowBuilder()], ExtraRowPosition.Below);

    Parameters

    • actionRows: ActionRowBuilder<MessageActionRowComponentBuilder>[]

      The action rows to add

    • position: ExtraRowPosition = ExtraRowPosition.Below

      The position where the action rows to be added

    Returns Pagination

  • Adds an attachment to the existing attachments.

    Example

    const pagination = new Pagination(interaction)
    .setAttachments([new AttachmentBuilder()])
    .addAttachment(new AttachmentBuilder());

    Parameters

    • attachment: BufferResolvable | Stream | JSONEncodable<APIAttachment> | Attachment | AttachmentBuilder | AttachmentPayload

      The attachment to add

    Returns Pagination

  • Adds multiple attachments to the existing attachments.

    Example

    const pagination = new Pagination(interaction)
    .setAttachments([new AttachmentBuilder()])
    .addAttachments([new AttachmentBuilder(), new AttachmentBuilder()]);

    Parameters

    • attachments: (BufferResolvable | Stream | JSONEncodable<APIAttachment> | Attachment | AttachmentBuilder | AttachmentPayload)[]

      The attachments to add

    Returns Pagination

  • Adds a authorized user who can use these pagination buttons.

    Example

    const pagination = new Pagination(interaction)
    .addAuthorizedUser(userId1);

    Parameters

    • authorizedUser: string

      The user to add

    Returns Pagination

  • Adds multiple authorized users who can use these pagination buttons.

    Example

    const pagination = new Pagination(interaction)
    .addAuthorizedUsers([userId1, userId2, userId3]);

    Parameters

    • authorizedUsers: string[]

      The users to add

    Returns Pagination

  • Adds multiple pagination descriptions.

    Example

    const pagination = new Pagination(interaction)
    .setDescriptions(["1st description", "2nd description", "3rd description"])
    .addDescriptions(["4st description", "5nd description", "6rd description"]);

    Parameters

    • Rest ...descriptions: RestOrArray<string>

      The descriptions to set

    Returns Pagination

  • Adds multiple pagination embeds.

    Example

    const pagination = new Pagination(interaction)
    .setEmbeds([new EmbedBuilder(), new EmbedBuilder(), new EmbedBuilder()])
    .addEmbeds([new EmbedBuilder(), new EmbedBuilder(), new EmbedBuilder()]);

    Parameters

    • embeds: (APIEmbed | JSONEncodable<APIEmbed>)[]

      An array of EmbedBuilder or APIEmbed

    • Optional template: ((embed) => JSONEncodable<APIEmbed>)

      A template function that will be called for each embed.

        • (embed): JSONEncodable<APIEmbed>
        • Parameters

          • embed: EmbedBuilder

          Returns JSONEncodable<APIEmbed>

    Returns Pagination

  • Appends fields to the embed

    Remarks

    This method accepts either an array of fields or a variable number of field parameters. The maximum amount of fields that can be added is 25.

    Example

    Using an array

    const fields: APIEmbedField[] = ...;
    const pagination = new Pagination(interaction)
    .addFields(fields);

    Example

    Using rest parameters (variadic)

    const pagination = new Pagination(interaction)
    .addFields(
    { name: 'Field 1', value: 'Value 1' },
    { name: 'Field 2', value: 'Value 2' },
    );

    Parameters

    • Rest ...fields: RestOrArray<APIEmbedField>

      The fields to add

    Returns Pagination

  • Edits the original reply with the final message.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.editReply();

    Returns Promise<Message<boolean>>

  • Sends the reply as a followUp.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.followUp();

    Returns Promise<Message<boolean>>

  • Goes to the first page.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.goFirst(i);

    Parameters

    • interaction: ButtonInteraction<CacheType>

      The interaction to reply to

    Returns Promise<void>

  • Goes to the last page.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.goLast(i);

    Parameters

    • interaction: ButtonInteraction<CacheType>

      The interaction to reply to

    Returns Promise<void>

  • Goes to the next page.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.goNext(i);

    Parameters

    • interaction: ButtonInteraction<CacheType>

      The interaction to reply to

    Returns Promise<void>

  • Goes to the previous page.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.goPrev(i);

    Parameters

    • interaction: ButtonInteraction<CacheType>

      The interaction to reply to

    Returns Promise<void>

  • Triggers the pagination to go to a specific page.

    Example

    const pagination = new Pagination(interaction)
    .setLimit(1)
    .setDescriptions(["1st page", "2nd page", "3rd page", "4th page", "5th page"]);
    ...
    pagination.goToPage(2);

    Parameters

    • pageNumber: number

      The page number to jump to

    Returns Pagination

  • Makes the pagination interactive.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.paginate(message);

    Parameters

    • message: Message<boolean> | InteractionResponse<true>

      The message to listen for interactions

    Returns Pagination

  • Paginates through fields. It will be ignored if you are not paginating through fields.

    Example

    const pagination = new Pagination(interaction)
    .setFields([{
    name: "Field 1",
    value: "Field 1 value",
    },
    {
    name: "Field 2",
    value: "Field 2 value",
    }])
    .paginateFields();

    Parameters

    • paginate: boolean = true

      Whether to paginate fields

    Returns Pagination

  • Sends the final message. By default, it will send as a reply to the message but if the interaction is already replied or deferred then it will editReply. If you want to send follow-up or update the interaction, then use followUp or update instead.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.render();

    Returns Promise<Message<boolean> | InteractionResponse<true>>

  • Replies the final message.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.reply();

    Returns Promise<Message<boolean> | InteractionResponse<true>>

  • Sends the final message in the interaction's channel.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.send();

    Returns Promise<Message<boolean>>

  • Sends an attachment along with the embed.

    Example

    const pagination = new Pagination(interaction)
    .setAttachments([new AttachmentBuilder()]);

    Parameters

    • attachments: (BufferResolvable | Stream | JSONEncodable<APIAttachment> | Attachment | AttachmentBuilder | AttachmentPayload)[]

      The attachments to set

    Returns Pagination

  • Sets the author of this embed.

    Parameters

    • options: null | EmbedAuthorOptions

      The options to use

    Returns Pagination

  • Sets authorized users who can use these pagination buttons. Leave it a empty array to allow everyone to use the pagination.

    Example

    const pagination = new Pagination(interaction)
    .setAuthorizedUsers([userId1, userId2, userId3]);

    Parameters

    • authorizedUsers: string[]

      The users to set

    Returns Pagination

  • Sets the description of this embed.

    Parameters

    • description: null | string

      The description to use

    Returns Pagination

  • Sets the pagination embeds. Note: if you set this then all other pagination methods and embed methods will be ignored i.e., descriptions, images, fields, also the embed properties like title, footer and all

    Example

    const pagination = new Pagination(interaction)
    .setEmbeds([new EmbedBuilder(), new EmbedBuilder(), new EmbedBuilder()]);

    Parameters

    • embeds: (APIEmbed | JSONEncodable<APIEmbed>)[]

      The embeds to set

    • Optional template: ((embed, i, array) => JSONEncodable<APIEmbed>)

      A template function that will be called for each embed.

        • (embed, i, array): JSONEncodable<APIEmbed>
        • Parameters

          • embed: EmbedBuilder
          • i: number
          • array: (APIEmbed | JSONEncodable<APIEmbed>)[]

          Returns JSONEncodable<APIEmbed>

    Returns Pagination

  • Sets the footer of this embed.

    Parameters

    • options: null | EmbedFooterOptions

      The footer to use

    Returns Pagination

  • Sets the image of this embed.

    Parameters

    • url: null | string

      The image URL to use

    Returns Pagination

  • Sets the pagination options.

    Example

    const pagination = new Pagination(interaction)
    .setOptions({
    firstEmoji: "⏮",
    prevEmoji: "◀️",
    nextEmoji: "▶️",
    lastEmoji: "⏭",
    limit: 5,
    idle: 5 * 60 * 1000,
    ephemeral: false,
    prevDescription: "",
    postDescription: "",
    attachments: [],
    buttonStyle: ButtonStyle.Secondary,
    loop: false,
    });

    Parameters

    • options: Partial<Options>

      The pagination options

    Returns Pagination

  • Sets a fixed post description which will be shown in all pages after the paginated descriptions. It will be ignored if you are not paginating through descriptions.

    Example

    const pagination = new Pagination(interaction)
    .setPostDescription("role id: 123456789");

    Parameters

    • postDescription: string

      The post description to set

    Returns Pagination

  • Sets a fixed prev description which will be shown in all pages before the paginated descriptions. It will be ignored if you are not paginating through descriptions.

    Example

    const pagination = new Pagination(interaction)
    .setPrevDescription("role info");

    Parameters

    • prevDescription: string

      The prev description to set

    Returns Pagination

  • Sets the thumbnail of this embed.

    Parameters

    • url: null | string

      The thumbnail URL to use

    Returns Pagination

  • Sets the timestamp of this embed.

    Parameters

    • Optional timestamp: null | number | Date

      The timestamp or date to use

    Returns Pagination

  • Sets the title for this embed.

    Parameters

    • title: null | string

      The title to use

    Returns Pagination

  • Sets the URL of this embed.

    Parameters

    • url: null | string

      The URL to use

    Returns Pagination

  • Removes, replaces, or inserts fields in the embed.

    Remarks

    This method behaves similarly to Array.prototype.splice. The maximum amount of fields that can be added is 25.

    It's useful for modifying and adjusting order of the already-existing fields of an embed.

    Example

    Remove the first field

    pagination.spliceFields(0, 1);
    

    Example

    Remove the first n fields

    const n = 4
    pagination.spliceFields(0, n);

    Example

    Remove the last field

    pagination.spliceFields(-1, 1);
    

    Parameters

    • index: number

      The index to start at

    • deleteCount: number

      The number of fields to remove

    • Rest ...fields: APIEmbedField[]

      The replacing field objects

    Returns Pagination

  • Serializes this builder to API-compatible JSON data.

    Remarks

    This method runs validations on the data before serializing it. As such, it may throw an error if the data is invalid.

    Returns APIEmbed

  • Updates the interaction's pagination.

    Example

    const pagination = new Pagination(interaction);
    ...
    pagination.update();

    Returns Promise<Message<boolean> | InteractionResponse<true>>

  • Parameters

    • other: APIEmbed | JSONEncodable<APIEmbed>

    Returns EmbedBuilder

Generated using TypeDoc