R
R
Radikulit2021-08-15 20:11:48
Python
Radikulit, 2021-08-15 20:11:48

Aiogram Bot: how to send multiple media as one photo collage?

If we reduce the bot as much as possible, we get the following code:

import logging
import conceptual_config

from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.markdown import *



API_TOKEN = conceptual_config.TOKEN  # Токен бота из личного файла

# Configure logging
logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN, parse_mode="html")
dp = Dispatcher(bot)



@dp.message_handler(commands=['start'])
async def send_welcome(message: types.Message):

    await message.answer("Бот принял команду /start")
    media_txt = "Превосходная \nФотография"

    media = [types.InputMediaPhoto('media/Starbucks_Logo.jpg', 'Превосходная фотография'), types.InputMediaPhoto('media/Starbucks_Logo_2.jpg')]  # Показываем, где фото и как её подписать
    await bot.send_chat_action(call.message.chat.id, types.ChatActions.UPLOAD_DOCUMENT)  # Устанавливаем action "Uploading a document..."
    await bot.send_media_group(call.message.chat.id, media=media)  # Отправка фото


if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)


But I still get an error:
aiogram.utils.exceptions.BadRequest: Wrong http url specified

I took it from this source: https://surik00.gitbooks.io/aiogram-lessons/conten...
I can't find out what is the reason and what is missing.

PS There is such a working option:
media = [types.InputMediaPhoto('media/Starbucks_Logo.jpg', 'Превосходная фотография')]  # Показываем, где фото и как её подписать
media.append(types.InputMediaPhoto('media/Starbucks_Logo_2.jpg'))
await types.ChatActions.upload_photo()  # Установка action "Отправка фотографии..."
await bot.send_media_group(message.chat.id, media=media)  # Отправка фото

But hunting to deal with that code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-15
@radikulit

media = types.MediaGroup()
media.attach_photo(types.InputFile('media/Starbucks_Logo.jpg'), 'Превосходная фотография')
media.attach_photo(types.InputFile('media/Starbucks_Logo_2.jpg'), 'Превосходная фотография 2')
await bot.send_media_group(call.message.chat.id, media=media)

There are examples in the library
https://github.com/aiogram/aiogram/blob/dev-2.x/ex...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question