# @discordx/pagination 中文文档

规范地址：https://npmcn.com/package/%40discordx/pagination/

版本：4\.4\.2
npm 元数据更新时间：2026-07-29T14:43:44.369Z
中文译文更新时间：2026-11-12T12:53:40.442Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40discordx/pagination
原文对照：https://npmcn.com/package/%40discordx/pagination/?lang=original
项目主页：https://discordx.js.org/
源码仓库：https://github.com/discordx-ts/discordx

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：98.8 kB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=16\.0\.0
- 运行依赖：1 个
- peer 依赖：discord\.js \>=14 \|\| ^14\.0\.0-dev
- 首次发布：2021-12-28T09:46:14.695Z
- 最新版本发布：2026-07-29T14:43:44.159Z
- 近 30 天下载量：2458（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：62（近 12 个月 2 个）

## 中文简介

在 Discord bots 创建 pagination 信件的库

## 安装

```sh
npm install @discordx/pagination
```

也可以使用：`pnpm add @discordx/pagination`、`yarn add @discordx/pagination`、`bun add @discordx/pagination`

## README

[![](https://discordx.js.org/discordx.svg)](https://discordx.js.org/)

[![Discord server](https://img.shields.io/discord/874802018361950248?color=5865F2&logo=discord&logoColor=white)](https://discordx.js.org/discord) [![NPM version](https://img.shields.io/npm/v/@discordx/pagination.svg?maxAge=3600)](https://www.npmjs.com/package/@discordx/pagination) [![NPM downloads](https://img.shields.io/npm/dt/@discordx/pagination.svg?maxAge=3600)](https://www.npmjs.com/package/@discordx/pagination) [![Build status](https://github.com/discordx-ts/discordx/workflows/Build/badge.svg)](https://github.com/discordx-ts/discordx/actions) [![paypal](https://img.shields.io/badge/donate-paypal-F96854.svg)](https://www.paypal.me/vijayxmeena)

**与 TypeScript 和 装饰器 创建不协调的机器人 !**

# 导 言

使用按钮或菜单添加 pagination 到不和的bot .

# \* 安装

需要16.6.0或更新的节点.js版本

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

# 倾斜

-   用不相通的新按钮嵌入页形并选择菜单
-   完全自定义( 如果您发现缺少一些东西, 可以打开一个问题, 这样我们可以修复) Name
-   大型列表支持(例1000项)
-   支助`embeds: (string | MessageEmbed | MessageOptions)[] | Pagination`(中文(简体) )
-   支持交互/信息/频道发送页面
-   动态使用的页面解析器

![discord embed pagination](https://github.com/discordx-ts/discordx/raw/main/packages/pagination/images/discord-embed-pagination.jpg)

## 示例

```ts
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();
  }
}
```

# 选项

## 基本选项

| 名称 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| 调试 | 布尔 | 虚假 | 启用调试日志 |
| 麻风 | 布尔 | 未定义 | 设定时空响应 |
| 初始页 | 编号 | 0 个 | 初始页码 |
| 设备 | 编号 | 未定义 | 选定菜单中每页显示的项目数 |
| 超时 | 函数 | 未定义 | 发卡时调用函数 |

## 按钮导航选项

以下备选方案可供选择: `buttons` 配置 :

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| 上一个 | 按钮选项 | 上一个按钮配置 |
| 向后键 | 按钮选项 | 后向按钮配置( 10页) |
| 转发 | 按钮选项 | 前进按钮配置( +10页) |
| 下一个 | 按钮选项 | 下一个按钮配置 |
| 退出 | 按钮选项 | 退出按钮配置 |
| 跳过自动挂载 | 编号 | 跳过按钮的页数( 默认: 10) |

### 按钮选项结构

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| 启用 | 布尔 | 在行中显示按钮 |
| 爱莫吉 | 组件 Emoji 可溶解 QQ 无效 | 按钮 emoji |
| 编号 | 字符串 | 自定义按钮ID |
| 标签 | 字符串 | 按钮标签文本 |
| 样式 | 按钮样式 | 按钮样式(PRIMARY ================= |

## 选择菜单选项

以下备选方案可供选择: `selectMenu` 配置 :

| 名称 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| 标签。 开始 | 字符串 | "开始" | 开始标签文本 |
| 标签.端 | 字符串 | "结束" | 结束标签文本 |
| 菜单 | 字符串 | "discordx@pagination@menu" (英语) | 自定义选中菜单ID |
| 页面文本 | 字符串 qq 字符串 \[\] | "页子 `{page}`" (中文(简体) ) | 页面文本格式( 使用) `{page}` 页面编号) |
| 位置持有人格式 | 字符串 | 未定义 | 自定义区域占位符格式( 使用) `{start}`, (中文(简体) ), `{end}`, (中文(简体) ), `{total}`(中文(简体) ) |

# 页:1

-   [unifix.js.org (英语)](https://discordx.js.org/)
-   [教学( dev.to)](https://dev.to/vijayymmeena/series/14317)

# 需要帮忙吗?

-   [检查常见问题](https://discordx.js.org/docs/faq)
-   [检查示例](https://github.com/discordx-ts/discordx/tree/main/packages/discordx/examples)
-   在社区里问 [Discord 服务器](https://discordx.js.org/discord)

# 谢谢

您可以支持 [调和x](https://www.npmjs.com/package/discordx) 给它一个 [GitHub 图像](https://github.com/discordx-ts/discordx) 明星们.

## 常见问题

### @discordx/pagination 是什么？

在 Discord bots 创建 pagination 信件的库

### 如何安装 @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 和提交记录判断。

