所以,我想通过消息获取所有的照片,但是我的代码只返回一张照片,而不是全部。
现在我有:
async def __photos(self, message: Message) -> None:
forwarded_message = message.reply_to_message
print(forwarded_message)这将返回message对象,该对象只包含一张照片的信息,而不是所有上传的照片。
发布于 2022-03-31 16:34:36
其中一种方法是使用,并保存所有文件id的
例如,可以是这样的:
@dp.message_handler(content_types=['photo'])
async def photo_handler(message: types.Message, state:FSMContext):
# we are here if the first message.content_type == 'photo'
# save the largest photo (message.photo[-1]) in FSM, and start photo_counter
await state.update_data(photo_0=message.photo[-1], photo_counter=0)
await state.set_state('next_photo')
@dp.message_handler(content_types=['photo'], state='next_photo')
async def next_photo_handler(message: types.Message, state:FSMContext):
# we are here if the second and next messages are photos
async with state.proxy() as data:
data['photo_counter'] += 1
photo_counter = data['photo_counter']
data[f'photo_{photo_counter}']=message.photo[-1]
await state.set_state('next_photo')
@dp.message_handler(state='next_photo')
async def not_foto_handler(message: types.Message, state:FSMContext):
# we are here if the second and next messages are not photos
async with state.proxy() as data:
# here you can do something with data dictionary with all photos
print(data)
await state.finish()https://stackoverflow.com/questions/71639290
复制相似问题