Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

📃 A lightweight Pagination module for Necord

License

NotificationsYou must be signed in to change notification settings

necordjs/pagination

Repository files navigation

📜 A lightweight Pagination module forNecord

Documentation ✨Source code 🪡Examples 🛠️Community 💬

NPM VersionNPM LicenseNPM DownloadsLast commit

About

Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured andmanageable way. When dealing with substantial volumes of data, such as search results, articles, or product listings, presenting it all atonce can overwhelm users and lead to a poor user experience. Pagination allows you to divide the information into smaller, organized chunks,enhancing user engagement and ease of navigation. This module allows you to create a pagination with a few lines of code.

Installation

Node.js 18.0.0 or newer is required.

$ npm i @necord/pagination necord discord.js$ yarn add @necord/pagination necord discord.js$ pnpm add @necord/pagination necord discord.js

Usage

Once the installation process is complete, we can import theNecordPaginationModule with yourNecordModule into the rootAppModule:

import{NecordModule}from'necord';import{Module}from'@nestjs/common';import{NecordPaginationModule}from'@necord/pagination';import{AppService}from'./app.service';@Module({imports:[NecordModule.forRoot({token:'DISCORD_BOT_TOKEN',intents:['Guilds','GuildMessages','DirectMessages']}),NecordPaginationModule.forRoot({// Change your buttons appearancebuttons:{},// Add buttons for skip to first and last pageallowSkip:true,// Add buttons for search pageallowTraversal:true,// Define the buttons position (start / end)buttonsPosition:'end'})],providers:[AppService]})exportclassAppModule{}

Then, we can inject thePaginationService into our service and register a pagination handler:

import{OnModuleInit,Injectable}from'@nestjs/common';import{NecordPaginationService,PageBuilder}from'@necord/pagination';import{Context,SlashCommand,SlashCommandContext}from'necord';@Injectable()exportclassAppServiceimplementsOnModuleInit{publicconstructor(privatereadonlypaginationService:NecordPaginationService){}publiconModuleInit():void{returnthis.paginationService.register(builder=>builder// Required, need for search your builder.setCustomId('test')// First way to set pages.setPages([newPageBuilder().setContent('Page 1'),newPageBuilder().setContent('Page 2'),newPageBuilder().setContent('Page 3'),newPageBuilder().setContent('Page 4'),newPageBuilder().setContent('Page 5')])// Second way, you can manually set pages using `setPages` method.setPagesFactory(page=>newPageBuilder().setContent(`Page${page}`))// Optional, only if you want to use pages factory.setMaxPages(5));}    @SlashCommand({name:'pagination',description:'Test pagination'})publicasynconPagination(@Context()[interaction]:SlashCommandContext){constpagination=this.paginationService.get('test');constpage=awaitpagination.build();returninteraction.reply(page);}}

Congratulations! You have successfully created your first pagination!Just usepagination command and you will see your pagination!

Registering Pagination Inside Command

You can also register pagination's dynamically inside your command handlers instead ofonModuleInit hook.

import{Injectable}from"@nestjs/common";import{NecordPaginationService,PageBuilder}from"@necord/pagination";import{Context,SlashCommand,SlashCommandContext}from"necord";@Injectable()exportclassAppService{publicconstructor(privatereadonlypaginationService:NecordPaginationService){}    @SlashCommand({name:"dynamic-pagination",description:"Register pagination inside command"})publicasynconDynamicPagination(@Context()[interaction]:SlashCommandContext){constpagination=this.paginationService.create(builder=>builder.setCustomId(`dynamic-${interaction.user.id}`).setFilter(i=>i.user.id===interaction.user.id).setPages([newPageBuilder().setContent("Dynamic Page 1"),newPageBuilder().setContent("Dynamic Page 2")]));constpage=awaitpagination.build();returninteraction.reply(page);}}

⚠️ You should ensure thatsetCustomId is unique per user/session if you register dynamically to avoid collisions.

You can view a working examplehere.

Backers

Stay in touch

License

MIT ©Alexey Filippov

About

📃 A lightweight Pagination module for Necord

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp