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

How to make multiple conditions on python next cord

So I want to make a command where for only a few certain people it says something specific and for the others that aren’t specified on the code, it will just say a normal thing.

@client.command()
async def test(ctx):
    if ctx.author.id == 1:
        await ctx.reply('Hello Person 1')
    if ctx.author.id == 2:
        await ctx.reply("Hello Person 2")
    if not ctx.author.id == 1 and 2:
        await ctx.reply ("Hello")

Something like the code above, which I did in fact try, but it will not count the second condition on line 7. Anyone have a solution?

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 :

ctx.author.id == 1 and 2

This is True if ctx.author.id == 1 and 2. Since 2 is not 0 and thus always truthy, the entire expression is always True if ctx.author.id == 1

The not then reverses that, so the entire expression as you used it is always True if ctx.author.id != 1

What you meant was:

not (ctx.author.id == 1 or ctx.author.id == 1)

Or:

ctx.author.id != 1 and ctx.author.id != 2

Or:

ctx.author.id not in [1, 2]

Even this does not work:

not ctx.author.id == (1 and 2)

Because that just computes 1 and 2 (neither is 0, so the result is a truthy 2). Not what you are after, since that just ends up testing if ctx.author.id equals 2 (confusingly).

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