Discord.JS - PaginationEmbed
A pagination utility for MessageEmbed in Discord.JS
📣 Notice Board
- Changelog
- Updating from
v1
- Recently updated to
v2
! If Documentation feels off, please clear site cache! - This utility no longer provide updates for v1 (Discord.JS 11)
🎉 Welcome
- ✔ Typings included
- ✔ Documentation for online references
- ✔ Asynchronous workflow
- ✔ Supports Discord.JS 12
- ❔ Nothing found within docs or need a nudge? You may visit the Discord server
🛠 Installation
- Requires Discord.JS 12:
npm install discord.js
- PaginationEmbed:
npm install discord-paginationembed
🔰 Examples
In-action samples:
- Pages of command description
- Toggle between character and its weapon, and toggle image visibility
- EXP Leaderboard
- Music Queue
⚠ Warning
- Examples are written under
message
event! - There are some methods not shown in the examples. If you want to know more methods to fiddle, please visit the Documentation
There are two modes of pagination
FieldsEmbed
Mode
- A pagination mode that uses a MessageEmbed with a field(s) containing the elements to paginate.
- Usually used for simple listing such as leaderboards and queues.
const Pagination = ; const FieldsEmbed = // A must: an array to paginate, can be an array of any type // Set users who can only interact with the instance. Default: `[]` (everyone can interact). // If there is only 1 user, you may omit the Array literal. // A must: sets the channel where to send the embed // Elements to show per page. Default: 10 elements per page // Have a page indicator (shown on message content). Default: false // Format based on the array, in this case we're formatting the page based on each object's `word` property ; // Customise embedFieldsEmbedembed ; // Deploy embedFieldsEmbed;
Working with Asynchronous Behaviour
This assumes this is under an
async
function
const Pagination = ; const FieldsEmbed = // Initial page on deploy // Deletes the embed upon awaiting timeout // Disable built-in navigation emojis, in this case: 🗑 (Delete Embed) // Set your own customised emojis // Similar to setFunctionEmojis() but this one takes only one emoji // Sets whether function emojis should be deployed after navigation emojis ; FieldsEmbedembed ; await FieldsEmbed; // Will not log until the instance finished awaiting user responses// (or techinically emitted either `expire` or `finish` event)console;
Embeds
Mode
- A pagination mode that uses an array of MessageEmbed to paginate.
- Usually used for complex builds such as characters' information.
const Discord = ;const Pagination = ; const embeds = ; for let i = 1; i <= 5; ++i embeds; const myImage = messageauthor; // Methods below are for customising all embeds ;
This assumes this is under an
async
function
const Discord = ;const Pagination = ; const embeds = ; for let i = 1; i <= 5; ++i embeds; const Embeds = // Sets the client's assets to utilise. Available options: // - message: the client's Message object (edits the message instead of sending new one for this instance) // - prompt: custom content for the message sent when prompted to jump to a page // {{user}} is the placeholder for the user mention // Listeners for PaginationEmbed's events // After the initial embed has been sent // (technically, after the client finished reacting with enabled navigation and function emojis). // When the instance is finished by a user reacting with `delete` navigation emoji // or a function emoji that throws non-Error type. // Upon a user reacting on the instance. // When the awaiting timeout is reached. // Upon an occurance of error (e.g: Discord API Error). ; await Embeds;
💡🐛💻 Contributing
Bug Reports
Please provide reproducible steps and results proofs (e.g: images). Also, solutions are welcome!
Suggestions / Discussions
Please be explicit about the feature's description and provide a valid reason (e.g: beneficial to users or development time) why it should be added/changed/removed.
Source Code
- Fork this repository.
- Execute
npm install
- Code and code and code and code and... code!
- To enable incremental compilation to JS:
npm run dev:watch
- To enable incremental compilation to JS:
npm test
to verify if your additions/adjustments are following the project's codebase rules and to verify if the docs are valid.- Please make sure that you have tested your changes very well.
- There is a test bot script under
test
folder. To get started:- Copy
credentials.sample.js
tocredentials.js
and fill up your private credentials (token, test channel, etc) - Execute either:
- One-time test:
npm run test:bot
- Hot-reloading test (nodemon):
npm run dev:start
- One-time test:
- Copy
- There is a test bot script under
- File a Pull Request (PR)!
- For the PR comment, it goes the same with
Suggestions / Discussions
.
License
© 2018-present Euni (gazmull)