0

my problem is that bot don't send photo, which it got from user(admin).Bot have to send photo all users in database.

@dp.message_handler(state='send_photo')
async def send(message: types.Message, state: FSMContext):
    photo = message.photo
    users = data.get_user()
    for el in users:
        try:
            await bot_name.send_photo(el[0],photo)
            if int(el[1]) != 1:
                data.set_active(el[0], 1)
        except:
            data.set_active(el[0], 0)
    await bot_name.send_message(message.from_user.id, 'The command was executed successfully!')
    await state.finish()

I tried to edit something with different ways and more times, but it was unsuccessful.

Zervan
  • 21
  • 2

1 Answers1

1

When you get the image through message_handler, it comes to you in the message as an array as shown below.

"photo": [
   {
    "file_id": "AgACAgIAAxkBAAEVtjtknKX0aBCod2........",
    "file_unique_id": "AQADEsw....",
    "file_size": 1199,
    "width": 90,
    "height": 70
   },
   {
    "file_id": "AgACAgIAAxkBAAEVtAAwIAA20AAy8E...........",
    "file_unique_id": "AQADEsw.......",
    "file_size": 10989,
    "width": 320,
    "height": 250
   },
   {
    "file_id": "AgACAgIAAxkBAAEVtjtknKX0aBCod22XuJ.......",
    "file_unique_id": "AQADEsw....",
    "file_size": 39728,
    "width": 800,
    "height": 624
   },
   {
    "file_id": "AgACAgIAAxkBAAEVtjtknKX0a.........",
    "file_unique_id": "AQADEswx......",
    "file_size": 52533,
    "width": 1000,
    "height": 780
   }
  ]

where image[0] is the lowest quality image and photo[-1] is the highest quality image.

You should rewrite the method as follows.

await bot_name.send_photo(el[0],photo[-1].file_id)

you can read more here

sendPhoto

file_id