fix: Improve error handling and logging for LevelingCog views to enhance user feedback and debugging

This commit is contained in:
Slipstream 2025-05-31 15:16:24 -06:00
parent fa5f39b1d3
commit 7860735f93
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -443,8 +443,13 @@ class LevelingCog(commands.Cog):
raise AssertionError("ui.TextDisplay returned None in LevelCheckView")
main_container.add_item(progress_text)
view = LevelCheckView(target, level, xp, xp_needed, next_level, bar, int(progress * 100))
await ctx.send(view=view)
try:
view = LevelCheckView(target, level, xp, xp_needed, next_level, bar, int(progress * 100))
await ctx.send(view=view)
except Exception as e:
print(f"Error creating level check view: {e}")
traceback.print_exc()
await ctx.send("❌ An error occurred while creating the level display. Please check the console for details.")
@level.command(name="leaderboard", description="Show the server's level leaderboard")
async def leaderboard_command(self, ctx: commands.Context):
@ -520,14 +525,19 @@ class LevelingCog(commands.Cog):
raise AssertionError("ui.Separator returned None between rows in LeaderboardView")
main_container.add_item(separator)
view = LeaderboardView(ctx.guild.name, sorted_data, guild_members)
# Double-check the view is dispatchable and properly constructed
if view is None:
return await ctx.send("❌ Failed to build leaderboard layout. Please try again.")
# Send the view
await ctx.send(view=view)
try:
view = LeaderboardView(ctx.guild.name, sorted_data, guild_members)
# Double-check the view is dispatchable and properly constructed
if view is None:
return await ctx.send("❌ Failed to build leaderboard layout. Please try again.")
# Send the view
await ctx.send(view=view)
except Exception as e:
print(f"Error creating leaderboard view: {e}")
traceback.print_exc()
await ctx.send("❌ An error occurred while creating the leaderboard. Please check the console for details.")
@level.command(name="register_role", description="Register a role for a specific level")
@commands.has_permissions(manage_roles=True)
@ -642,8 +652,13 @@ class LevelingCog(commands.Cog):
main_container.add_item(separator)
view = ListLevelRolesView(ctx.guild, self.level_roles[ctx.guild.id])
await ctx.send(view=view)
try:
view = ListLevelRolesView(ctx.guild, self.level_roles[ctx.guild.id])
await ctx.send(view=view)
except Exception as e:
print(f"Error creating list level roles view: {e}")
traceback.print_exc()
await ctx.send("❌ An error occurred while creating the level roles list. Please check the console for details.")
@level.command(name="restrict_channel", description="Restrict a channel from giving XP")
@commands.has_permissions(manage_channels=True)
@ -862,8 +877,13 @@ class LevelingCog(commands.Cog):
except AttributeError:
command_prefix = "!" # Fallback if ctx.prefix doesn't exist
view = XPConfigView(self.config, command_prefix)
await ctx.send(view=view)
try:
view = XPConfigView(self.config, command_prefix)
await ctx.send(view=view)
except Exception as e:
print(f"Error creating XP config view: {e}")
traceback.print_exc()
await ctx.send("❌ An error occurred while creating the configuration display. Please check the console for details.")
return
if not value:
@ -1192,8 +1212,13 @@ class LevelingCog(commands.Cog):
gender_detection_section.add_item(gender_desc)
main_container.add_item(gender_detection_section)
view = MedievalRolesSetupView(created_roles, updated_roles, has_pronoun_roles)
await status_message.edit(content=None, view=view)
try:
view = MedievalRolesSetupView(created_roles, updated_roles, has_pronoun_roles)
await status_message.edit(content=None, view=view)
except Exception as e:
print(f"Error creating medieval roles setup view: {e}")
traceback.print_exc()
await status_message.edit(content="❌ An error occurred while creating the setup summary. Please check the console for details.")
async def setup(bot: commands.Bot):
await bot.add_cog(LevelingCog(bot))