skip to Main Content

I’m making a telegram bot in Python that edits an image.

Tell me how to make it so that the user can send only one image in a message? But how can you control the number of images in a message from a user via the API?

I read the TelegramAPI documentation, but didn’t find anything on this topic. It seems to me that you cannot prevent a user from sending multiple images in one message. But then I would like the bot to see an attempt to send it several photos at a time and report this to the user.

Thanks for the answer 🙂

2

Answers


  1. Chosen as BEST ANSWER

    Thanks everyone! Solved the problem with the help of Aditya Yadav's comment. Solution below:

    @bot.message_handler(content_types=['photo']) if not message.media_group_id: def function(message): ... else: bot.send_message(message.chat.id, "Please send only one image!")


  2. How about comparing the files’ extensions each time a user sends a message? For instance, the message could have a .png or .jpg suffix and there could be a limitation for their number of usage.

    Could be useful to check the message’s content, first.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search