@bot.slash_command()
@discord.option("role", description="Role you would like to display.", type=discord.Role, required=True)
async def setrole(ctx, role: discord.Role):
author_id = ctx.author.id
author_roles = []
author_record = session.query(UserRoles).filter_by(user_id=author_id).first()
author_unlocked_roles = json.loads(author_record.unlocked_roles)
role_id = role.id
set_role = discord.utils.get(ctx.guild.roles, id=role_id)
if not author_record:
await ctx.respond("You do not have any unlocked roles", ephemeral=True)
return
else:
if role_id not in author_unlocked_roles:
await ctx.respond("You do not have this role unlocked.", ephemeral=True)
return
else:
if set_role in ctx.author.roles:
await ctx.respond("You already have this role selected", ephemeral=True)
return
else:
emblem_role_present = False
for role1 in ctx.author.roles:
if role1.icon:
await ctx.author.remove_roles(role1)
await ctx.author.add_roles(role)
emblem_role_present = True
break
if emblem_role_present:
await ctx.respond(f"Successfully set display role to {role.name}.", ephemeral=True)
else:
await ctx.author.add_roles(role)
await ctx.respond(f"Successfully set display role to {role.name}.", ephemeral=True)
I have a command which I would hope adds the role specified in the command and removes any roles with icons from the user
however after 2 uses of the command working fine, it seems to just add the role and not remove the role with the icon