0

I seem unable to find the solution as to why this doesn't work here's the line of code:

if ("yeah" or "yes") in message.content:
  await message.channel.send("yep")
else:
  await message.channel.send("nope")

I tried using any and even a word list but it didn't work either

what I mean to say is that if any of the words "yeah" or "yes" (or even more) appear in a sentence then the bot must send "yep" if not then it should say "nope"

macropod
  • 12,757
  • 2
  • 9
  • 21

1 Answers1

0

You can check against multiple values using a combination of in and any. It essentially creates a list of boolean values, then checks if any of them are true (i.e. one of the words exists in the message).

if any(x in message.content for x in ["yeah", "yes"]):
    # send "yep"
else:
    # send "nope"

This solution is based off this answer

bluecouch
  • 193
  • 3
  • 12
  • is x supposed to be something? or should it be left as is? thanks for typing it out! – Shane Miller Apr 06 '22 at 02:53
  • `x` is a variable that is set to each value in the list as it iterates of the list. For example, `x` will become `"yeah"` and then `"yes"` in this example, at which point it is checked if it is in `message.content`. So you can leave `x` as is. – bluecouch Apr 06 '22 at 02:56