Options
Dark
  • Light
  • Dark
All
  • Public
  • Public/Protected
  • All
Menu

discord.js-paginator

Codacy Badge GitHub package.json version GitHub LICENSE Maintenance Docs Build Status

A simple reaction-based paginator for discord.js.

Installation

# For stable
npm i @shane4368/discord.js-paginator

# For development (requires git)
npm i shane4368/discord.js-paginator

Compatibility

This package does not work with discord.js v11 and previous versions. Only discord.js v12 is currently supported.

Examples

See full documentation.

Basic setup

const { Paginator } = require("@shane4368/discord.js-paginator");

const paginator = new Paginator({ userID: message.author.id });

// Log message when destroyed or timed out.
paginator.on("end", console.log);
// Log error when it occurs.
paginator.on("error", console.error);

// {0} - first occurrence will be replaced with current page number.
// {1} - first occurrence will be replaced with total page count.
paginator.addPage("This is the first page.\n\nPage {0}/{1}")
    .addPage("This is the second page.\n\nPage {0}/{1}")
    .addPage("This is the third page.\n\nPage {0}/{1}")
    .addPage("This is the fourth page.\n\nPage {0}/{1}");

// Ensure your function is async before using 'await' keyword.
await paginator.start(message.channel).catch(console.error);

Miscellaneous

// Setting embed template.
paginator.setEmbedTemplate({
    color: 0x00b6eb,
    title: "Constant Title",
    footer: {
        text: "Custom footer format {0}/{1}"
    }
});

// Adding embed pages.
paginator.addPage({ description: "This is the first page." })
    .addPage({ description: "This is the second page." });

// Disabling front, rear and trash emojis.
paginator.setEmojis({ front: null, rear: null, trash: null });
// Overriding defaults for front, rear and trash emojis.
paginator.setEmojis({ front: "👈", rear: "👉", trash: "474075113176825866" });

Notes

  • Place the page number format in the footer text when using an embed. If no footer is present, one will be automatically created.

Index

Type aliases

PaginatorData

PaginatorData: { circular: boolean; content: string | null; deleteOnTimeout: boolean; embed: MessageEmbed | null; emojis: Partial<PaginatorEmojis> | null; infoOptions: PaginatorInfoOptions; jumpOptions: PaginatorJumpOptions; pages: (string | MessageEmbed)[]; timeout: number; userID: string | null }

Type declaration

  • circular: boolean

    If set to true, the pages will loop on 'back' and 'next.'

    default

    true

  • content: string | null

    The text to be displayed when using embed pages.

  • deleteOnTimeout: boolean

    Whether or not to delete the paginator when timed out.

    default

    false

  • embed: MessageEmbed | null

    Embed template to use across pages. All properties on this object will be shown on every page.

  • emojis: Partial<PaginatorEmojis> | null

    The emojis to use for skipping the pages. Specify the id for custom guild emojis.

  • infoOptions: PaginatorInfoOptions

    Options to use for the 'info' emoji.

  • jumpOptions: PaginatorJumpOptions

    Options to use for the 'jump' emoji.

  • pages: (string | MessageEmbed)[]

    The pages to use in the paginator. Must contain at least one page.

  • timeout: number

    The time in milliseconds of how long to keep the paginator running.

    default

    120000

  • userID: string | null

    The id of the user to listen to.

PaginatorEmojis

PaginatorEmojis: { back: string; front: string | null; info: string | null; jump: string | null; next: string; rear: string | null; stop: string | null; trash: string | null }

Type declaration

  • back: string
    default

    "◀"

  • front: string | null
    default

    "⏮"

  • info: string | null
    default

    "ℹ️"

  • jump: string | null
    default

    "🔢"

  • next: string
    default

    "▶"

  • rear: string | null
    default

    "⏭"

  • stop: string | null
    default

    "⏹️"

  • trash: string | null
    default

    "🗑"

PaginatorInfoOptions

PaginatorInfoOptions: { text: string; timeout: number }

Type declaration

  • text: string
    default

    "This is a paginator. React to change page."

  • timeout: number
    default

    5000

PaginatorJumpOptions

PaginatorJumpOptions: { deleteResponse: boolean; prompt: string; showPrompt: boolean; timeout: number }

Type declaration

  • deleteResponse: boolean
    default

    true

  • prompt: string
    default

    "Enter page number to jump to."

  • showPrompt: boolean

    Whether or not to show prompt.

    default

    true

  • timeout: number
    default

    10000

Legend

  • Constructor
  • Property
  • Method
  • Inherited method

Generated using TypeDoc