M
M
mxmgzr2021-06-13 16:29:50
Photo
mxmgzr, 2021-06-13 16:29:50

How to implement the bot sending an album of photos in telegram?

There was a difficulty with sending a photo in a telegram bot. Here is my code:

@bot.message_handler(regexp='Скинь мне фото!')
def photo_album(message):
    ph1 = open('\Temp\KL.py\photo_2021-06-13_13-54-47.jpg', 'rb')
    bot.send_photo(message.chat.id, ph1)
    ph2 = open('\Temp\KL.py\photo_2021-06-13_13-54-49.jpg', 'rb')
    bot.send_photo(message.chat.id, ph2)
    ph3 = open('\Temp\KL.py\photo_2021-06-13_13-54-43.jpg', 'rb')
    bot.send_photo(message.chat.id, ph3)
    ph4 = open('\Temp\KL.py\photo_2021-06-13_13-54-45.jpg', 'rb')
    bot.send_photo(message.chat.id, ph4)
    ph5 = open('\Temp\KL.py\photo_2021-06-13_13-54-46.jpg', 'rb')
    bot.send_photo(message.chat.id, ph5)
    ph6 = open('\Temp\KL.py\photo_2021-06-13_13-54-50.jpg', 'rb')
    bot.send_photo(message.chat.id, ph6)
    ph7 = open('\Temp\KL.py\photo_2021-06-13_13-54-52.jpg', 'rb')
    bot.send_photo(message.chat.id, ph7)


Implemented crookedly, so I ask for advice.
How can I send photos in one album?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Altry, 2021-06-14
@Altry

media  = types.MediaGroup()
media.attach_photo(types.InputFile('путь_к_файлу'), 'название,которое будет отображаться')# повторяеете этот метод столько раз , сколько фоток будет в альбоме
await bot.send_media_group(message.from_user.id, media=media)

I don’t know what language and framework you are writing in, so here is a link to this method in the official documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question