Dendi1
Dendi1

Reputation: 11

Send multiple photos with text aiogram

I can send several photos like this:

group = []
for photo in photos2:
    group.append(InputMediaPhoto(media=photo))
await message.answer_media_group(group, caption="Text123", text='Text123')

But caption and text don't work

I can also send a photo with text but only one await message.answer_photo(photo=photo, caption=caption)

But I can't find how to send several photos with text I looked at the aiogram documentation but didn't find the answer to my question. How to do it?

aiogram 3.4.1

Upvotes: 1

Views: 1133

Answers (1)

Exorsky
Exorsky

Reputation: 15

Try this one. Showing my example as reference:

from aiogram.utils.media_group import MediaGroupBuilder

@router.message(UploadPostAd.photos)
async def process_photos( message: Message, state: FSMContext):
    # Process the photos here
    if message.photo:
        photo_ids = get_all_photo_ids(message)  # Get all photo IDs

        media_group = MediaGroupBuilder(caption="Media group caption")
        for photo in photo_ids:
            media_group.add_photo(type="photo", media=photo)

        await message.answer_media_group(media=media_group.build())
        await state.clear()

Upvotes: 0

Related Questions