导 言
使用按钮或菜单添加 pagination 到不和的bot .
* 安装
需要16.6.0或更新的节点.js版本
npm install @discordx/pagination
yarn add @discordx/pagination
倾斜
- 用不相通的新按钮嵌入页形并选择菜单
- 完全自定义( 如果您发现缺少一些东西, 可以打开一个问题, 这样我们可以修复) Name
- 大型列表支持(例1000项)
- 支助
embeds: (string | MessageEmbed | MessageOptions)[] | Pagination(中文(简体) ) - 支持交互/信息/频道发送页面
- 动态使用的页面解析器

示例
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
需要帮忙吗?
- 检查常见问题
- 检查示例
- 在社区里问 Discord 服务器