Okay so basically when one does ~promote @user it promotes them to Head Coach. When they do the command again it should promote them to general manager but it doesnt do anything and says "Promoted to Head Coach!" Again. Here’s my code, any help?
GM = discord.utils.get(guild.roles, name="General Manager")
HC = discord.utils.get(guild.roles, name="Head Coach")
Nor = discord.utils.get(guild.roles, name="Houston Texans")
if (Nor in user.roles) and (not HC) or (GM):
await user.add_roles(HC)
await ctx.send("Promoted to Head Coach!")
elif HC in user.roles:
await user.add_roles(GM)
await user.remove_roles(HC)
await ctx.send("Promoted to General Manager!")
elif GM in user.roles:
await ctx.send("Cannot go any higher than General Manager!")`
Ive tried alot of stuff and just doesnt seem to work. Ive asked around and every answer i’ve got still doesnt work and does the same thing.
>Solution :
There is a problem in your first condition. You test if the user has the role Nor, then if HC does not exist, then if GM does exist.
Python interprets it like this :
if ((Nor in user.roles) and (not HC)) or (GM)
This is always true (if the role exists in the server), because you declared this variable earlier.
You should rewrite it like the following :
GM = discord.utils.get(guild.roles, name="General Manager")
HC = discord.utils.get(guild.roles, name="Head Coach")
if HC in user.roles: # promote from HC to GM
await user.add_roles(GM)
await user.remove_roles(HC)
await ctx.send("Promoted to General Manager!")
elif GM in user.roles: # already GM, can't go higher
await ctx.send("Cannot go any higher than General Manager!")
else: # promote from base role to HC
await user.add_roles(HC)
await ctx.send("Promoted to Head Coach!")