discord-msg-pagination
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

Discord Message Pagination

Discord Message Pagination is an addon for Discord.js. It helps you to create paginated messages using slash commands and message components (Buttons) if your content is too long for one message.

Installation

Node.js v16.6.0 or newer is required.

npm install discord-msg-pagination

Optional packages

Usage

Quick start using embed array

import { sendPaginatedEmbed } from 'discord-msg-pagination';

sendPaginatedEmbed(interaction, embeds);

Using a custom function to update message embed dynamically

onPageChange will be called whenever a button interaction happens.

import { sendPaginatedEmbed } from 'discord-msg-pagination';

function onPageChange(pageNumber, embed) {
  return embed
    .setTitle(`This is page #${pageNumber}`);
}

sendPaginatedEmbed(interaction, initialEmbed, { onPageChange });

Options

interface Options {
  /**
   * Text to be displayed on next button
   */
  nextLabel?: string,
  /**
   * Text to be displayed on previous button
   */
  previousLabel?: string,
  /**
   * How long the buttons will work (defaults to 10min)
   */
  time?: number,
  /**
   * Button style
   */
  style?: ButtonStyle,
  /**
   * Function which will run if the page changed. Only if second argument is not an array. 
   */
  onPageChange?: (event: 'next' | 'previous' | string, embed: EmbedBuilder) => EmbedBuilder | Promise<EmbedBuilder>,
  /**
   * Message content
   */
  content?: string,
  /**
   * Add custom components to render above the pagination buttons
   */
  components?: ActionRowBuilder<any>[],
  /**
   * Specifiy a restriction for pagination buttons
   */
  restriction?: 'ALL' | 'AUTHOR' | ((member: GuildMember) => boolean | Promise<boolean>),
  /**
   * Set a start index. Default index is 0
   */
  startIndex?: number,  
  /**
   * Send ephemeral response
   */
  ephemeral?: boolean
}

Local test

Set your DISCORD_BOT_TOKEN to your .env.

cp .env.sample .env

npm run test:bot

Readme

Keywords

Package Sidebar

Install

npm i discord-msg-pagination

Weekly Downloads

1

Version

2.3.0

License

ISC

Unpacked Size

20 kB

Total Files

13

Last publish

Collaborators

  • larrrssss