You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在aiogram的message_handler装饰器中获取Update对象?

在aiogram中同时获取Message和Update对象

在aiogram的message_handler装饰器中,直接给处理函数添加update: types.Update参数即可,框架会自动注入Update对象。

修改后的示例代码:

@dp.message_handler()
async def kb_answer(update: types.Update, message: types.Message):
    # 可同时使用update与message对象进行业务处理
    pass

参数顺序不影响框架的注入逻辑,按照自己的习惯声明即可。

内容的提问来源于stack exchange,提问作者rasputin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 11:31:02