A view paginator for discord.py
This paginator is your best choice if you want to display
- large amounts of data (image gallery)
- Live generating data (any database)
Keep in mind that this paginator is very complex and requires decent discord.py knowledge
If you need any help regarding my paginator you can contact me here (do not ask in the discord.py server, they don't help with third-party libaries)
This library is tested with discord.py v2.3.1:
pip install git+https://github.com/philskillz-coder/discord-py-paginator
Step by step:
- Create a class with
paginator.Paginator
as its parent - Create the
Paginator.page_update
method:
- In this method you get the interaction object and the current page passed.
- In this method you can use the interaction object as in your commands.
- Create the
Paginator.get_page_count
method (or set thestatic_page_count
variable):
- In this method you get the interaction object passed.
- Returns, how many pages you have. If you no page limit, return
None
or dont implement this method.
from discord.ext.paginator import paginator
class GuildPaginator(paginator.Paginator):
async def get_page_count(self, interaction: Interaction) -> int:
return len(self.client.guilds)
async def page_update(self, interaction: Interaction, current_page: int):
guild = self.client.guilds[current_page]
return await interaction.response.edit_message(
content=f"Guild {current_page + 1}/{await self.get_page_count(interaction)}",
embed=(
Embed(
title="Guild",
colour=Color.green()
)
.add_field(name="Name", value=guild.name)
.add_field(name="ID", value=str(guild.id))
.add_field(name="Member count", value=str(guild.member_count), inline=False)
),
view=self
)
@bot.command(
name="guilds",
description="Show all the guilds"
)
async def show_guilds(ctx):
await ctx.send(
content="The bot guilds",
view=await GuildPaginator(
ctx.bot,
ctx.author
).run()
)
additionally you implement these methods
Paginator.page_validator
(custom page number validator)Paginator.search_page
(search for the first occurrence of a value on a page)Paginator.on_setup
(invoked when the paginator instance is created)Paginator.on_start
(invoked when a user clicked the start button)Paginator.on_stop
(invoked when a user clicked the stop button)
Examples on all methods and features can be found in the examples folder
Click me
# v2.1.5 -> v2.1.6:
- Added InstantPaginator (without start button)
- Added more examples
# v2.1.4 -> v2.1.5:
- Added page_validator method
# v2.1.3 -> v2.1.4:
- Added kwargs to the Paginator class (passed to view)
# v2.1.2 -> v2.1.3:
- Added new config option _button_hidden
- Merged InfinitePaginator into Paginator (Paginator is now infinite by default)
# v2.1.1 -> v2.1.2:
- Added InfinitePaginator
Issue reports are appreciated. You can report one via
- the repositories issues page
- my Discord Server
- Discord direct message to
philskillz_
thanks in advance.
All config options can be found in config.md file
Examples can be found in examples folder