import discord from discord.ext import commands class PaginateView(discord.ui.View): def __init__(self, pages): super().__init__(timeout=60.0) self.pages = pages self.current_page = 0 async def update_message(self, interaction: discord.Interaction): await interaction.response.edit_message(embed=self.pages[self.current_page], view=self) @discord.ui.button(label='Previous', style=discord.ButtonStyle.primary, emoji='<:previous:1249402557839839274>') async def previous(self, button: discord.ui.Button, interaction: discord.Interaction): self.current_page = (self.current_page - 1) % len(self.pages) await self.update_message(interaction) @discord.ui.button(label='Next', style=discord.ButtonStyle.primary, emoji='<:next:1249402769719169146>') async def next(self, button: discord.ui.Button, interaction: discord.Interaction): self.current_page = (self.current_page + 1) % len(self.pages) await self.update_message(interaction) @discord.ui.button(label='Navigate', style=discord.ButtonStyle.secondary, emoji='<:navigate:1249402947536818226>') async def navigate(self, button: discord.ui.Button, interaction: discord.Interaction): def check(msg): return msg.author == interaction.user and msg.channel == interaction.channel await interaction.response.send_message('Please enter the page number:', ephemeral=True) try: msg = await interaction.client.wait_for('message', check=check, timeout=30.0) page_number = int(msg.content) - 1 if 0 <= page_number < len(self.pages): self.current_page = page_number await self.update_message(interaction) else: await interaction.followup.send('Invalid page number.', ephemeral=True) except ValueError: await interaction.followup.send('Invalid input. Please enter a number.', ephemeral=True) except discord.TimeoutError: await interaction.followup.send('Timed out waiting for your response.', ephemeral=True) @discord.ui.button(label='Cancel', style=discord.ButtonStyle.danger, emoji='<:cancel:1249403113111162972>') async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction): await interaction.message.delete() async def paginate(ctx, pages): view = PaginateView(pages) await ctx.send(embed=pages[0], view=view)