F
F
fright0022022-03-03 04:11:55
Python
fright002, 2022-03-03 04:11:55

How to make the bot give a response if it sees a certain word in a message?

An example of an ordinary bot reaction to a specific message

if message_text == 'Привет':
    bot.send_message(message.chat.id, 'И тебе привет')

How to make the message be valid "Blah blah blah, back and forth, yesterday-today, text text text, Hello" and the bot caught the text "hello" from this message, and responded to it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
2
21terra, 2022-03-03
@fright002

use in
if "hello" in message.text.lower():
bot.send_message(message.chat.id, "Hello to you too")
Note that message.text.lower() takes a word and converts it to lowercase, those. HELLO will be treated as hello. So use words only in small letters, no capital letters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question