@discordx/pagination

中文文档
4.4.2发布于 2026/07/29Apache-2.0TypeScriptESM + CJS近 30 天下载 2458

Library for creating pagination messages in Discord bots

原始使用文档
文档目录5 节
  1. Example
  2. Basic Options
  3. Button Navigation Options
  4. ButtonOptions Structure
  5. Select Menu Options

Discord server NPM version NPM downloads Build status paypal

Create a discord bot with TypeScript and Decorators!

📖 Introduction

Add pagination to discord bot using buttons or menu.

💻 Installation

Version 16.6.0 or newer of Node.js is required

npm install @discordx/pagination
yarn add @discordx/pagination

Pagination

  • Embed pagination with discord's new buttons and select menu
  • fully customizable (You can open an issue if you find something missing, so that we can fix it)
  • Large list support (for examples 1000 items)
  • Support (embeds: (string | MessageEmbed | MessageOptions)[] | Pagination)
  • support interaction/message/channel to send pages
  • page resolver for dynamic usage

discord embed pagination

Example

import { Pagination, PaginationResolver } from "@discordx/pagination";
import {
  ActionRowBuilder,
  ButtonBuilder,
  ButtonStyle,
  EmbedBuilder,
  Events,
  type CommandInteraction,
  type MessageActionRowComponentBuilder,
} from "discord.js";
import { Discord, On, Slash, type ArgsOf } from "discordx";

function GeneratePages(limit?: number): MessageOptions[] {
  const pages = Array.from(Array(limit ?? 20).keys()).map((i) => {
    return { content: `I am ${i + 1}`, embed: `Demo ${i + 1}` };
  });
  return pages.map((page) => {
    return {
      content: page.content,
      embeds: [new MessageEmbed().setTitle(page.embed)],
    };
  });
}

@Discord()
export class Example {
  // example: message
  @On({ event: Events.MessageCreate })
  async messageCreate([message]: ArgsOf<Events.MessageCreate>): Promise<void> {
    if (message.content === "paginated demo") {
      const pagination = new Pagination(message, GeneratePages());
      await pagination.send();
    }
  }

  // example: any text channel
  @On({ event: Events.MessageCreate })
  async messageCreateChannel([
    message,
  ]: ArgsOf<Events.MessageCreate>): Promise<void> {
    if (message.content === "paginated channel demo") {
      const pagination = new Pagination(message.channel, GeneratePages());
      await pagination.send();
    }
  }

  // Example: simple slash with button pagination
  @Slash({ description: "Simple slash with button pagination", name: "demo-a" })
  async demoA(interaction: CommandInteraction): Promise<void> {
    const resolver = new PaginationResolver((page, paginator) => {
      // Let's update our pagination dynamically
      if (page === 3) {
        // Set pages, this can can be resolver as well
        paginator.setPages([
          { content: "1" },
          { content: "2" },
          { content: "3" },
          { content: "4" },
          { content: "5" },
        ]);

        return { content: "Pagination updated" };
      }

      return { content: `page v2 ${page + 1}` };
    }, 25);

    const pagination = new Pagination(interaction, resolver, {
      onTimeout: async () => {
        try {
          await interaction.deleteReply();
        } catch (err) {
          // ignore
        }
      },
      buttons: {
        backward: {
          emoji: { name: "🙂" },
        },
      },
      time: 60_000,
    });

    await pagination.send();
  }

  // example: simple slash with menu pagination
  @Slash({ description: "Simple slash with menu pagination", name: "demo-b" })
  async demoB(interaction: CommandInteraction): Promise<void> {
    const pagination = new Pagination(interaction, GeneratePages(), {
      time: 60_000,
    });

    await pagination.send();
  }

  // example: simple string array
  @Slash({ description: "Simple string array", name: "demo-c" })
  async demoC(interaction: CommandInteraction): Promise<void> {
    const pagination = new Pagination(
      interaction,
      Array.from(Array(200).keys()).map((i) => ({
        content: (i + 1).toString(),
      })),
    );

    await pagination.send();
  }

  // example: array of custom message options
  @Slash({ description: "Array of custom message options", name: "demo-d" })
  async demoD(interaction: CommandInteraction): Promise<void> {
    const pagination = new Pagination(interaction, [
      {
        content: "Page 1",
      },
      {
        content: "Page 2",
        embeds: [new EmbedBuilder({ title: "It's me embed 2" })],
      },
      {
        components: [
          new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
            [
              new ButtonBuilder({
                customId: "myCustomId",
                label: "My Custom Button",
                style: ButtonStyle.Primary,
              }),
            ],
          ),
        ],
        content: "Page 3",
        embeds: [new EmbedBuilder({ title: "It's me embed 3" })],
      },
    ]);

    await pagination.send();
  }
}

Options

Basic Options

NameTypeDefaultDescription
debugbooleanfalseEnable debug logging
ephemeralbooleanundefinedSet ephemeral response
initialPagenumber0Initial page number
itemsPerPagenumberundefinedNumber of items shown per page in select menu
onTimeoutFunctionundefinedCallback function when pagination times out

Button Navigation Options

The following options are available under the buttons configuration:

NameTypeDescription
previousButtonOptionsPrevious button configuration
backwardButtonOptionsBackward button configuration (-10 pages)
forwardButtonOptionsForward button configuration (+10 pages)
nextButtonOptionsNext button configuration
exitButtonOptionsExit button configuration
skipAmountnumberNumber of pages to skip with skip buttons (default: 10)

ButtonOptions Structure

NameTypeDescription
enabledBooleanShow button in row
emojiComponentEmojiResolvable | nullButton emoji
idstringCustom button ID
labelstringButton label text
styleButtonStyleButton style (PRIMARY|SECONDARY|SUCCESS|DANGER)

Select Menu Options

The following options are available under the selectMenu configuration:

NameTypeDefaultDescription
labels.startstring"Start"Start label text
labels.endstring"End"End label text
menuIdstring"discordx@pagination@menu"Custom select menu ID
pageTextstring | string[]"Page {page}"Page text format (use {page} for page number)
rangePlaceholderFormatstringundefinedCustom range placeholder format (use {start}, {end}, {total})

📜 Documentation

☎️ Need help?

💖 Thank you

You can support discordx by giving it a GitHub star.

版本与发布记录

@discordx/pagination 共发布 62 个版本,首次发布于 2021/12/28;过去 12 个月发布了 2 个版本。

版本发布日期距今
4.4.2latest2026/07/293 个月前
4.4.12026/06/154 个月前
4.4.02025/08/281.2 年前
4.3.02025/08/211.2 年前
4.2.02025/08/211.2 年前
4.1.02025/08/041.3 年前

其他发布通道:dev → 4.0.0-dev.1670073642.4821b1ea。

关于 @discordx/pagination 的常见问题

@discordx/pagination 是什么?

Library for creating pagination messages in Discord bots

如何安装 @discordx/pagination?

在项目目录运行 npm install @discordx/pagination,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:discord.js(>=14 || ^14.0.0-dev)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@discordx/pagination 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@discordx/pagination 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@discordx/pagination 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@discordx/pagination 可以商用吗?

@discordx/pagination 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@discordx/pagination 的下载量有多少?

根据 npm 官方下载统计,@discordx/pagination 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,458 次,日均约 82 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@discordx/pagination 还在维护吗?

最新版本 4.4.2 发布于 2026/07/29(3 个月前);至今共发布 62 个版本,其中过去 12 个月发布了 2 个;首次发布于 2021/12/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。