-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfinite_paginator.py
26 lines (22 loc) · 1 KB
/
infinite_paginator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import discord
from discord.ext.paginator import Paginator
from typing import Optional
# This is a paginator with infinite pages
class MyInstantPaginator(Paginator):
async def page_validator(self, interaction: discord.Interaction, page: int, max_page: Optional[int]) -> bool:
# in here you could implement a custom page validation
# for example numbers can not be negative
# explanation:
# We didn't set a page limit hence the paginator doesn't jump to the last page after jumping back from the first page,
# so we need to implement a custom page validation to prevent the user from going to negative pages
return page >= 0
async def page_update(self, interaction: discord.Interaction, current_page: int):
return await self.edit_or_send( # this is a helper function
interaction,
embed=(
discord.Embed(
title=f"Number {current_page}",
)
),
view=self
)