0

написал код:


@client.event
async def on_message(message):
    if "word" or "apple" or "juice" in message.content:
          await message.channel.send("Something")
    await client.process_commands(message)```

после запуска данного кода, бот начинает бесконечно спамить в чат слово "Something"

1 ответ 1

0

Это выражение всегда True:

if "word" or "apple" or "juice" in message.content:

Если логически разделить его, то будет:

if ("word") or ("apple") or ("juice" in message.content):

А т.к. if "word" всегда True, то проверять дальше нет смысла

Правильно будет так:

if "word" in message.content or "apple" in message.content or "juice" in message.content:

UPD.

Кст, если слов много, то список слов можно проверить через функцию any:

if any(word in message.content for word in ["word", "apple", "juice"]):

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.