Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import disnake
- from disnake.enums import ButtonStyle
- class Pagination(disnake.ui.View):
- message: disnake.Message
- def __init__(self, embeds: list[disnake.Embed]) -> None:
- super().__init__(timeout=None)
- self.embeds = embeds
- self.index = 0
- self._update_state()
- def _update_state(self) -> None:
- self.overview.disabled = self.prev_page.disabled = self.index == 0
- self.end_page.disabled = self.next_page.disabled = self.index == len(self.embeds) - 1
- async def on_error(self, error: Exception, item: disnake.ui.Button, inter: disnake.MessageInteraction) -> None:
- """Called if the interaction check failed or any other errors occur within this view"""
- await inter.response.send_message(
- "You Do Not Have Permission To Interact With This Paginator. Contact Support Staff If This Is An Error.",
- ephemeral=True)
- async def interaction_check(self, interaction: disnake.MessageInteraction) -> bool:
- return interaction.message.interaction.author == interaction.author
- @disnake.ui.button(label="Overview", style=disnake.ButtonStyle.primary)
- async def overview(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
- self.index = 0
- self._update_state()
- await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
- @disnake.ui.button(label="Previous", style=disnake.ButtonStyle.secondary)
- async def prev_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
- self.index -= 1
- self._update_state()
- await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
- @disnake.ui.button(label="Next", style=disnake.ButtonStyle.secondary)
- async def next_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
- self.index += 1
- self._update_state()
- await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
- @disnake.ui.button(label="End", style=disnake.ButtonStyle.primary)
- async def end_page(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
- self.index = -1
- self._update_state()
- await interaction.response.edit_message(embed=self.embeds[self.index], view=self)
- class CategoryPaginator(Pagination):
- @disnake.ui.button(label="Home", style=ButtonStyle.blurple)
- async def home_button(self, inter):
- await inter.response.defer()
- guild = inter.guild.id
- # build table of contents embed
- embed = disnake.Embed(
- color = disnake.Colour.random(),
- title = f"{guild.name} Of Applications",
- description = "Select A Category Below To View Those Projects"
- ).set_thumbnail(url = guild.icon)
- topics = ["Beginner Projects", "Intermediate Projects", "WebScraping Projects",
- "Automation Projects", "TKinter Projects", "Turtle Projects", "OpenCV Projects",
- "PythonDjango Projects", "Python TTS Projects", "Other Projects"]
- options = [
- disnake.SelectOption(label = topic, value=str(i)) for i, topic in enumerate(topics, start=1)
- ]
- select = disnake.ui.Select(
- placeholder="Select A Category",
- options=options,
- max_values=1,
- custom_id = "meks_hub_category_selector"
- )
- await inter.edit_original_message(embed=embed, components=select)
Advertisement
Add Comment
Please, Sign In to add comment