@acegoal07/discordjs-pagination 中文文档教程

发布于 3年前 浏览 16 项目主页 更新于 3年前

discordjs-pagination

Repository size npm NPM npm (prod) dependency version Libraries.io dependency status for latest release GitHub contributors Monthly Downloads


关于   |   例子   |   确定   |   NPM   |   作者


About

必需的依赖项:

  • discord.js version 13.5.0^

安装使用:

npm i @acegoal07/discordjs-pagination

使用交互分页时,您可以在调用分页之前延迟回复,因为它支持延迟和非延迟交互

如果您提供的分页少于 2 个嵌入,它将自动发送没有按钮的嵌入作为普通嵌入

如果您不想要自定义按钮,您可以使用 autoButton 选项,这会替换 buttonList 选项并为您创建按钮

可以找到此分页的包装器 here 但目前不包含在最新版本的分页中

Make sure

调用分页时确保它是没有括号的 pagination({ })不会工作

如果你想使用 autoDelete 或带有交互分页的删除按钮,如果你已经推迟了你不能启用临时的回复

Example

// Import the @acegoal07/discordjs-pagination package
const pagination = require('@acegoal07/discordjs-pagination');
const { MessageEmbed , MessageButton } = require('discord.js');

// Use MessageEmbed to make pages
// Keep in mind that Embeds should't have their footers set since
// the pagination will overwrite the set footer
const embed1 = new MessageEmbed()
   .setTitle('First Page')
   .setDescription('This is the first page');
const embed2 = new MessageEmbed()
   .setTitle('Second Page')
   .setDescription('This is the second page');

// Use MessageButton to create the buttons
// Do not used link buttons as they don't give an output
const button1 = new MessageButton()
   .setCustomId('previousbtn')
   .setLabel('Previous')
   .setStyle('DANGER');
const button2 = new MessageButton()
   .setCustomId('nextbtn')
   .setLabel('Next')
   .setStyle('SUCCESS');
// The delete button is optional and is not required for
// pagination to work
const button3 = new MessageButton()
   .serCustomId('delbtn')
   .setLabel('Delete')
   .setStyle('DANGER');
const button4 = new MessageButton()
   .serCustomId('lastbtn')
   .setLabel('Last Page')
   .setStyle('Success');
const button5 = new MessageButton()
   .serCustomId('firstbtn')
   .setLabel('First page')
   .setStyle('DANGER');

// Create an array of embeds
pageList = [
    embed1,
    embed2
   // ... Can add as many embeds as you want
];

// Create an array of buttons
buttonList = [
   button1, // Next page button
   button2, // Previous page button
   button3 // Optional delete button (do not include if you do not want it)
];
// To use the first and last buttons use
buttonList = [
   button5, // First page button
   button1, // Next page button
   button2, // Previous page button
   button4, // Last page button
   button3 // Optional delete button (do not include if you do not want it)
];

// Create timeout amount
const timeout = 3000;
// Timeout is how long the collector will listen to the buttons till
// turing off if you do not include the timeout it defaults to 12000
// and the minimum time that can be set is 3000 any lower will result in error

// For messages use
pagination({
   message, // Required
   pageList, // Required
   buttonList, // Required

   autoButton: true, // optional - if you do not want custom buttons remove the buttonList parameter
                     // and replace it will autoButtons: true which will create buttons depending on
                     // how many pages there are
   autoDelButton: true, // Optional - if you are using autoButton and would like delete buttons this 
                        // parameter adds delete buttons to the buttonList

   timeout, // Optional - if not provided it will default to 12000ms

   replyMessage: true, // Optional - An option to reply to the target message if you do not want
                       // this option remove it from the function call

   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar

   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
});

// For interaction use
pagination({
   interaction, // Required
   pageList, // Required
   buttonList, // Required

   autoButton: true, // Optional - if you do not want custom buttons remove the buttonList parameter
                     // and replace it will autoButtons: true which will create buttons depending on
                     // how many pages there are
   autoDelButton: true, // Optional - if you are using autoButton and would like delete buttons this 
                        // parameter adds delete buttons to the buttonList

   timeout, // Optional - if not provided it will default to 12000ms

   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call  

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar

   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
});

discordjs-pagination

Repository size npm NPM npm (prod) dependency version Libraries.io dependency status for latest release GitHub contributors Monthly Downloads


About   |   Example   |   Make Sure   |   NPM   |   Author


About

Required dependency:

  • discord.js version 13.5.0^

To install use:

npm i @acegoal07/discordjs-pagination

When using the interaction pagination you are able to defer the reply before calling pagination as it supports both deferred and non deferred interaction

If you supply the pagination with less than 2 embeds it will automaticity send the embed without the buttons as a normal embed

If you do not want custom buttons you can use the autoButton option this replaces the buttonList option and creates the buttons for you

A wrapper for this pagination can be found here but as of the moment is not included in the most recent version of the pagination

Make sure

When calling the pagination make sure it is pagination({ }) without the brackets it won't work

If you want to use either autoDelete or the delete buttons with a interaction pagination if you have already deferred the reply you can't have ephemeral enabled

Example

// Import the @acegoal07/discordjs-pagination package
const pagination = require('@acegoal07/discordjs-pagination');
const { MessageEmbed , MessageButton } = require('discord.js');

// Use MessageEmbed to make pages
// Keep in mind that Embeds should't have their footers set since
// the pagination will overwrite the set footer
const embed1 = new MessageEmbed()
   .setTitle('First Page')
   .setDescription('This is the first page');
const embed2 = new MessageEmbed()
   .setTitle('Second Page')
   .setDescription('This is the second page');

// Use MessageButton to create the buttons
// Do not used link buttons as they don't give an output
const button1 = new MessageButton()
   .setCustomId('previousbtn')
   .setLabel('Previous')
   .setStyle('DANGER');
const button2 = new MessageButton()
   .setCustomId('nextbtn')
   .setLabel('Next')
   .setStyle('SUCCESS');
// The delete button is optional and is not required for
// pagination to work
const button3 = new MessageButton()
   .serCustomId('delbtn')
   .setLabel('Delete')
   .setStyle('DANGER');
const button4 = new MessageButton()
   .serCustomId('lastbtn')
   .setLabel('Last Page')
   .setStyle('Success');
const button5 = new MessageButton()
   .serCustomId('firstbtn')
   .setLabel('First page')
   .setStyle('DANGER');

// Create an array of embeds
pageList = [
    embed1,
    embed2
   // ... Can add as many embeds as you want
];

// Create an array of buttons
buttonList = [
   button1, // Next page button
   button2, // Previous page button
   button3 // Optional delete button (do not include if you do not want it)
];
// To use the first and last buttons use
buttonList = [
   button5, // First page button
   button1, // Next page button
   button2, // Previous page button
   button4, // Last page button
   button3 // Optional delete button (do not include if you do not want it)
];

// Create timeout amount
const timeout = 3000;
// Timeout is how long the collector will listen to the buttons till
// turing off if you do not include the timeout it defaults to 12000
// and the minimum time that can be set is 3000 any lower will result in error

// For messages use
pagination({
   message, // Required
   pageList, // Required
   buttonList, // Required

   autoButton: true, // optional - if you do not want custom buttons remove the buttonList parameter
                     // and replace it will autoButtons: true which will create buttons depending on
                     // how many pages there are
   autoDelButton: true, // Optional - if you are using autoButton and would like delete buttons this 
                        // parameter adds delete buttons to the buttonList

   timeout, // Optional - if not provided it will default to 12000ms

   replyMessage: true, // Optional - An option to reply to the target message if you do not want
                       // this option remove it from the function call

   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar

   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
});

// For interaction use
pagination({
   interaction, // Required
   pageList, // Required
   buttonList, // Required

   autoButton: true, // Optional - if you do not want custom buttons remove the buttonList parameter
                     // and replace it will autoButtons: true which will create buttons depending on
                     // how many pages there are
   autoDelButton: true, // Optional - if you are using autoButton and would like delete buttons this 
                        // parameter adds delete buttons to the buttonList

   timeout, // Optional - if not provided it will default to 12000ms

   autoDelete: true, // Optional - An option to have the pagination delete it's self when the timeout ends
                     // if you do not want this option remove it from the function call  

   privateReply: true, // Optional - An option to have the pagination sent in a dm
                      // if you do not want this option remove it from the function call

   // Optional - An option to have the footer replaced by a progress bar
   // if you do not want this option remove it from the function call
   progressBar: true, // Required if you want to use the progressBar
   proSlider: "▣", // Optional if you want a custom progressBar
   proBar: "▢", // Optional if you want a custom progressBar

   authorIndependent: true // Optional - An option to set pagination buttons only usable by the author
                           // if you do not want this option remove it from the function call
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文