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

python-telegram-bot报错:'ExtBot'对象无'reply_to'属性,如何回复消息?

解决Telegram Bot reply_to 属性报错的方案

问题原因

在python-telegram-bot v20+版本中,ExtBot 对象不再提供 reply_to 方法,原有的回复功能需要通过 send_message 方法配合参数实现。

修正后的代码

async def lockdown(update: telegram.Update, context: ext.ContextTypes):
    sender_id = update.message.from_user.id
    if sender_id == 7472:
        print("YEA")  
    else:
        await context.bot.send_message(
            chat_id=update.message.chat_id,
            text="NO.",
            reply_to_message_id=update.message.message_id
        )

核心说明

  • 使用send_message替代reply_to,这是ExtBot支持的标准消息发送方法
  • 通过chat_id指定消息发送的对话ID,text设置回复内容
  • 添加reply_to_message_id参数并传入原消息的message_id,即可实现回复目标消息的效果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 14:12:08