Socket
Socket
Sign inDemoInstall

discord-msg-pagination

Package Overview
Dependencies
26
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    discord-msg-pagination

A pagination utility for Messages in discord.js using message components


Version published
Maintainers
1
Install size
13.0 MB
Created

Readme

Source

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

  • discord-embed-colors to easily convert hex colors to decimal numbers used in discord embeds

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

Keywords

FAQs

Last updated on 15 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc