Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discord py promote command

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading