Made it so if a button would do nothing it will be grayed out on the xp lb

This commit is contained in:
Lilac-Rose
2025-10-22 18:41:57 +02:00
parent 26040a4209
commit b85ffd5bd5

View File

@@ -10,11 +10,20 @@ class LeaderboardView(View):
super().__init__(timeout=60)
self.embed_pages = embed_pages
self.current_page = 0
self.update_button_states()
async def update_message(self, interaction: discord.Interaction):
self.update_button_states()
embed = self.embed_pages[self.current_page]
await interaction.response.edit_message(embed=embed, view=self)
def update_button_states(self):
# Disable "Previous" if on first page
self.previous.disabled = self.current_page == 0
# Disable "Next" if on last page
self.next.disabled = self.current_page == len(self.embed_pages) - 1
@discord.ui.button(label="⬅️ Previous", style=discord.ButtonStyle.secondary)
async def previous(self, interaction: discord.Interaction, button: Button):
if self.current_page > 0:
@@ -27,6 +36,17 @@ class LeaderboardView(View):
self.current_page += 1
await self.update_message(interaction)
async def on_timeout(self):
for child in self.children:
if isinstance(child, Button):
child.disabled = True
if hasattr(self, "message") and self.message:
try:
await self.message.edit(view=self)
except discord.NotFound:
pass
class Leaderboard(commands.Cog):
def __init__(self, bot):
@@ -114,6 +134,8 @@ class Leaderboard(commands.Cog):
view = LeaderboardView(embeds)
await interaction.response.send_message(embed=embeds[0], view=view)
view.message = await interaction.original_response()
async def setup(bot):
await bot.add_cog(Leaderboard(bot))