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

Python if/else explanation

I wanted to make a Discord bot for my Server and I need help by finding out if the Person is an Mod or not.

Here’s the Code:

@client.hybrid_command(description="All Commands")
async def cmds(ctx):
if has_role('HCRP | Staff Team'):
print("Is Staff")

else:
print("Is Member")

I want it to tell me what Role the Person has but it says always is Staff.

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 :

@client.hybrid_command(description="all commands")
async def cmds(ctx:commands.Context):
    guild = ctx.guild
    role = guild.get_role(ROLE_ID)
    if role in ctx.author.roles:
        print("Is Staff")
    else:
        print("Is Member")

In this code we define the guild which is the server the command was executed on. Then use the guild.get_role() function to define the role by it’s id. Then we check if that role is the ctx.author's roles.

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