英文:
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)
您可以在这里了解更多信息 👇
英文:
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 👇
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论