How to send media group by id?

Viewed 43

I am writing a telegram bot and at one point a group of files, be it photos, videos or documents, arrives at the entrance. After that, I get the id of this media group. For example: "13301881925488218". I enter this id into the database and later I need to get a group of media files that I sent using this ID. I thought it was possible to send them this way, but nothing happened.

media = types.MediaGroup()
media.attach_photo(photo=str(data[0][6])) # data[0][6] is the id of the media group
await bot.send_media_group(callback_query.message.chat.id, media=media)
1 Answers

I've solve the problem

media = types.MediaGroup()
docs = types.MediaGroup()
for i in range(len(out_media)):
    if out_media[i][0] == "document":
        docs.attach_document(document=out_media[i][1])
    elif out_media[i][0] == "photo":
        media.attach_photo(photo=out_media[i][1])
    elif out_media[i][0] == "video":
        media.attach_video(video=out_media[i][1])

try:
    await bot.send_media_group(callback_query.message.chat.id, media=media)
except:
    pass

try:
    await bot.send_media_group(callback_query.message.chat.id, media=docs)
except:
    pass
Related