为什么机器人不发送照片?

huangapple go评论72阅读模式
英文:

Why bot don't send photo?

问题

以下是您提供的代码的翻译部分:

@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()

请告诉我您需要的任何其他帮助。

英文:

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.

答案1

得分: 1

当通过message_handler获取图像时,它将以如下所示的方式作为message中的数组传递给您。

"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
   }
  ]

其中 image[0] 是最低质量的图像,而 photo[-1] 是最高质量的图像。

您应该按照以下方式重写该方法。

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

您可以在这里了解更多信息 👇

sendPhoto

file_id

英文:

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

huangapple
  • 本文由 发表于 2023年6月27日 19:02:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564200.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定