D
D
duuuuuuuden2021-06-17 21:59:43
Python
duuuuuuuden, 2021-06-17 21:59:43

How to make the bot react to a certain word only when there is an image in the message?

I’ve been tinkering with this for the third day now, I can’t find any information.
The message to the bot must contain certain text and an image, only in this case it must react.
If the message contains only this specific text or only an image, then it should not react.
If you use:

@bot.message_handler(content_types=['photo'])
def handle_message(message):
    if message.text == "слово":
        (Сделать что то)

He doesn't react at all

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Krostelev, 2021-06-17
@duuuuuuuden

it is necessary to compare not the entire text with the "word", but to look for the occurrence of the "word" in the text of the message.
if "слово" in message.text:
It may even be worth referring not to the text field, but to the caption field. Experiment.

S
soremix, 2021-06-17
@SoreMix

Уже третий день с этим ковыряюсь, не могу найти никакой информации

Do print(message), you will see all the fields of the object. It will immediately be clear that you need a field caption, and nottext

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question