B
B
bongerka2020-05-24 11:25:37
Bots
bongerka, 2020-05-24 11:25:37

How to send a photo via telebot?

There was a problem with send_photo. I don't understand how the message.photo list works. What do the elements of this list mean? Why can select [-1] element?
I decided to test the code so that the number of elements of the message.photo list is displayed, for one photo the bot sends either 2 or 3, how is this possible if I threw off one photo?

@bot.message_handler(content_types=['photo'])

def gg(message):
    bot.send_message(message.chat.id, str(len(message.photo)))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
del4pp, 2020-05-24
@bongerka

-1 element is the last one (often when they don't know the length of the list and want to take the last one - write exactly minus one),
Send a photo via telebot:

photo = open('путь_к_фото', 'rb')
bot.send_photo(chat_id, photo)

You also have a decorator
@bot.message_handler(content_types=['photo'])
. It works with photos that users sent to the bot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question