Welcome!
It's a very simple paginator for discord-py-interactions!
This project is open source ⭐.
Install
pip install --upgrade SlashPaginator
Example
@slash.slash(name="example")
async def _example(ctx):
embed1 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 1")
embed2 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 2")
embed3 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 3")
paginator = SlashPaginator.AutoSlashEmbedPaginator(ctx)
embeds = [embed1, embed2, embed3]
await paginator.run(embeds)
The AutoSlashEmbedPaginator uses the lib's buttons to scroll.
If given only one page, it just acts as a glorified ctx.send(embed=embeds) message.
The CustomAutoSlashPaginator is a subclass of AutoSlashEmbedPaginator that lets you:
- Customise what buttons you want to use, instead of the default.
- Customize what functions the buttons should use instead.
The caveat with the custom object is that it requires learning about how to use components in the lib. You may refer here to learn more.
Custom example (Reimplementing AutoSlashEmbedPaginator without the freeze page button):
class MyOwnPaginator(SlashPaginator.CustomAutoSlashPaginator):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
async def button_1_action(self, button_ctx):
"""Seeks to the first page."""
self.current_page = 0
if self.remove_reactions:
try:
await button_ctx.edit_origin(components=[])
except:
pass
if self.auto_footer:
self.embeds[0].set_footer(
text=f"({self.current_page + 1}/{len(self.embeds)})"
)
await button_ctx.edit_origin(embed=self.embeds[0])
async def button_2_action(self, button_ctx):
"""Seeks to the previous page."""
self.current_page = self.current_page - 1
self.current_page = (
0 if self.current_page < 0 else self.current_page
)
if self.remove_reactions:
try:
await button_ctx.edit_origin(components=[])
except:
pass
if self.auto_footer:
self.embeds[self.current_page].set_footer(
text=f"({self.current_page + 1}/{len(self.embeds)})"
)
await button_ctx.edit_origin(embed=self.embeds[self.current_page])
async def button_3_action(self, button_ctx):
"""Seeks to the next page."""
self.current_page = self.current_page + 1
self.current_page = (
len(self.embeds) - 1
if self.current_page > len(self.embeds) - 1
else self.current_page
)
if self.remove_reactions:
try:
await button_ctx.edit_origin(components=[])
except:
pass
if self.auto_footer:
self.embeds[self.current_page].set_footer(
text=f"({self.current_page + 1}/{len(self.embeds)})"
)
await button_ctx.edit_origin(embed=self.embeds[self.current_page])
async def button_4_action(self, button_ctx):
"""Seeks to the last page."""
self.current_page = len(self.embeds) - 1
if self.remove_reactions:
try:
await button_ctx.edit_origin(components=[])
except:
pass
if self.auto_footer:
self.embeds[len(self.embeds) - 1].set_footer(
text=f"({self.current_page + 1}/{len(self.embeds)})"
)
await button_ctx.edit_origin(
embed=self.embeds[len(self.embeds) - 1]
)
@slash.slash(name="example")
async def _example(ctx):
embed1 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 1")
embed2 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 2")
embed3 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 3")
emojis = ["⏮️", "◀", "▶", "⏭️"] # first page, prev page, next page, last page
embeds = [embed1, embed2, embed3]
paginator = MyOwnPaginator(ctx, control_emojis=emojis)
await paginator.run(embeds)
Custom Example #2
(Redoing the look of the buttons, but keep the functionality intact.)
@slash.slash(name="example")
async def _example(ctx):
embed1 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 1")
embed2 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 2")
embed3 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 3")
emojis = ["⏮️", "◀", "⏹️", "▶", "⏭️"] # first page, prev page, stop, next page, last page
embeds = [embed1, embed2, embed3]
paginator = SlashPaginator.CustomAutoSlashPaginator(ctx, control_emojis=emojis, default_run=True)
await paginator.run(embeds)
License
This project is under the MIT License.
Contribute
Anyone can contribute to this by forking the repository, making a change, and create a pull request!
Make sure you run it under the black formatter first :)
Credits to:
- decave27 for the README layout
- toxicrecker for the basis of this paginator
- Everyone that maintains the discord-py-interactions lib.
Metadata
Release files for SlashPaginator 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| SlashPaginator-0.0.3.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| SlashPaginator-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.3 kB
Release files / SlashPaginator-0.0.3.tar.gz
| Download URL | SlashPaginator-0.0.3.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5058c887b6b2225c02b14cdd24e009163854b1dd10a7a02e34cd92c45fd620dc
|
|
BLAKE2b-256 checksum How to use checksums |
ea943e4c38a23a58bd87ea1bd169b6cd07f31b62ddde1f5e34b08ccc82264fd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
|
Release files / SlashPaginator-0.0.3-py3-none-any.whl
| Download URL | SlashPaginator-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
903ff7e233dcc387b85cf91e1fb4e454aa6b6c5de8eb360e7bec14cb1877103a
|
|
BLAKE2b-256 checksum How to use checksums |
04cf73d49d125288af611d48d82e27d57dfd29c21c7ff79ce22f010eb6a93689
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
|