From e8e4b7e471fe8d49000fb1b8b46672eb8e8d31ea Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Mon, 24 Feb 2025 14:13:09 +0100 Subject: [PATCH] Added cleanup in allow_role and cleaned output messages --- reginaldCog/reginald.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index ddfd8d4..ee686b6 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -490,10 +490,13 @@ class ReginaldCog(commands.Cog): @commands.has_permissions(administrator=True) async def allow_role(self, ctx, role: discord.Role): async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles: - if role.id not in allowed_roles: - allowed_roles.append(role.id) - await self.config.guild(ctx.guild).allowed_roles.set(allowed_roles) # Save change - await ctx.send(f"DEBUG: Role {role.id} added. Current allowed_roles: {allowed_roles}") + # ✅ Clean list of invalid roles before adding new one + valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)] + + if role.id not in valid_roles: + valid_roles.append(role.id) + await self.config.guild(ctx.guild).allowed_roles.set(valid_roles) # Save change + await ctx.send(f"✅ Role `{role.name}` has been granted access to Reginald.") else: await ctx.send(f"⚠️ Role `{role.name}` already has access.") @@ -501,7 +504,6 @@ class ReginaldCog(commands.Cog): @commands.has_permissions(administrator=True) async def disallow_role(self, ctx, role: discord.Role): async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles: - # Remove invalid roles valid_roles = [role_id for role_id in allowed_roles if ctx.guild.get_role(role_id)] await self.config.guild(ctx.guild).allowed_roles.set(valid_roles)