Skip to content

Commit

Permalink
[CustomRoles] fix custom role deletion if role's been deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
noahkw committed Feb 2, 2024
1 parent 1bde2b7 commit 4f0bccb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cogs/CustomRoles.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ async def delete(self, ctx: commands.Context):
if custom_role is None:
raise commands.BadArgument("You do not currently have a custom role.")

role_name = custom_role.role.name
await custom_role.role.delete(
reason=f"Custom role for {ctx.author} ({ctx.author.id}) removed manually"
)
await db.delete_custom_role(session, ctx.guild.id, ctx.author.id)
if custom_role.role:
role_name = custom_role.role.name
await custom_role.role.delete(
reason=f"Custom role for {ctx.author} ({ctx.author.id}) removed manually"
)
await ctx.reply(f"Your role '{role_name}' has been deleted.")
else:
await ctx.reply("Your role has been deleted.")

await db.delete_custom_role(session, ctx.guild.id, ctx.author.id)
await session.commit()
await ctx.reply(f"Your role '{role_name}' has been deleted.")

@custom_roles.command(brief="Creates a custom role for you")
@has_guild_role()
Expand Down Expand Up @@ -155,6 +158,7 @@ async def on_user_blocked(self, blocked_user: BlockedUser):
return

await self.delete_custom_role(session, custom_role)
await session.commit()

async def delete_custom_role(self, session, custom_role: CustomRole) -> None:
try:
Expand Down

0 comments on commit 4f0bccb

Please sign in to comment.