V
V
Vladimir2021-09-17 08:21:25
Python
Vladimir, 2021-09-17 08:21:25

How to prevent telegram bot from responding to group photos?

There is a bot that responds to each photo / image, but if you send a group of photos at once (say 5 pcs), then the bot immediately returns 5 answers in a row. How can this be fixed? Maybe there is some function so that the bot responds only every 2 seconds, for example. Or the processing option for group photos, maybe some.

(pyTelegramBotAPI)

import telebot

@bot.message_handler(content_types=['text', 'photo', 'files'])
def give_photo(message):
    if message.content_type == 'photo':
        bot.send_message(message.chat.id, text="ОТВЕТ") 

if __name__ == '__main__':
     bot.infinity_polling()

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Old_TyT, 2021-09-17
@Old_TyT

You can use the key in the dictionary (media_gropup_id)
On the left is the answer to get a group of photos, on the right to get one photo
614431a150956027363115.jpeg

R
rPman, 2021-09-17
@rPman

Remember the time of the last photo, and if the current time and the previous one differ by less than a second, skip everything and do not send a message

R
robprane, 2021-09-17
@robprane

Even focusing on media_group_id will not be enough, because the user may not group photos, or send files of different types, in which case they will not be grouped anyway. It is necessary to redo the logic of the bot, taking into account the fact that several files can come from the user at any time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question