-2

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?

RickBloxx
  • 1
  • 2
  • Does this answer your question? [How to test multiple variables for equality against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-for-equality-against-a-single-value) – TheFungusAmongUs May 19 '22 at 22:05

2 Answers2

0
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 == 2)

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).

Grismar
  • 27,561
  • 4
  • 31
  • 54
-1

While Python may look like English, it is in fact not English. In English, I can say, "today is hot and sunny", and it means that today is hot and today is sunny. However, computers don't work like that. They cannot infer things that way, and so you need to be explicit, such as:

if not (ctx.author.id == 1 and ctx.author.id == 2):
    await ctx.reply ("Hello")
Epic Programmer
  • 383
  • 3
  • 12