mekasu0124

Untitled

Feb 10th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. import disnake
  2.  
  3.  
  4. class Pagination(disnake.ui.View):
  5.     message: disnake.Message
  6.  
  7.     def __init__(self, embeds: list[disnake.Embed], author: disnake.Member | disnake.User) -> None:
  8.         super().__init__(timeout=None)
  9.         self.author = author
  10.         self.embeds = embeds
  11.         self.index = 0
  12.         self._update_state()
  13.  
  14.     def _update_state(self) -> None:
  15.         self.overview.disabled = self.prev_page.disabled = self.index == 0
  16.         self.end_page.disabled = self.next_page.disabled = self.index == len(self.embeds) - 1
  17.  
  18.     async def on_error(self, error: Exception, item: disnake.ui.Button, inter: disnake.MessageInteraction) -> None:
  19.         """Called if the interaction check failed or any other errors occur within this view"""
  20.  
  21.         await inter.response.send_message(
  22.             "You Do Not Have Permission To Interact With This Paginator. Contact Support Staff If This Is An Error.",
  23.             ephemeral=True)
  24.  
  25.     async def interaction_check(self, interaction: disnake.MessageInteraction) -> bool:
  26.         return self.author.id == interaction.author.id
  27.  
  28.     @disnake.ui.button(label="Overview", style=disnake.ButtonStyle.primary)
  29.     async def overview(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
  30.         self.index = 0
  31.         self._update_state()
  32.  
  33.         await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
  34.  
  35.     @disnake.ui.button(label="Previous", style=disnake.ButtonStyle.secondary)
  36.     async def prev_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
  37.         self.index -= 1
  38.         self._update_state()
  39.  
  40.         await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
  41.  
  42.     @disnake.ui.button(label="Next", style=disnake.ButtonStyle.secondary)
  43.     async def next_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
  44.         self.index += 1
  45.         self._update_state()
  46.  
  47.         await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
  48.  
  49.     @disnake.ui.button(label="End", style=disnake.ButtonStyle.primary)
  50.     async def end_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
  51.         self.index = -1
  52.         self._update_state()
  53.  
  54.         await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
Add Comment
Please, Sign In to add comment