【问题标题】:python-telegram-bot. AttributeError: "Update" object has no attribute "reply_to_message"蟒蛇电报机器人。 AttributeError:“更新”对象没有属性“reply_to_message”
【发布时间】:2021-07-13 16:32:27
【问题描述】:

我正在尝试使用python-telegram-bot 开发一个聊天机器人。

假设它的功能之一包括提取发送消息的用户的用户名和已使用命令回复消息的用户的用户名。

根据文档,一旦我们的应用收到Update 对象,它应该包含属性reply_to_message,这将使任务像下面的sn-p 一样简单:

# The callback which will handle the command
def extract(self, update, context):
    if update.message.reply_to_message.from_user.username == 'bot_username':
        update.message.reply_text("Something")
    else:
        target = update.message.reply_to_message.from_user.username
        user= update.message.from_user.username

如果我没有被误导,如果我们从 Bot Father 关闭了 \setprivacy 设置,这应该可以工作,但如果我回复由bot 而不是回复普通用户。

我哪里错了?任何帮助是极大的赞赏。谢谢。

P.S - 这是我在社区中的第一个问题。我希望我清楚地解释了这个问题。

这个问题已经在Python Telegram Bot. Get message to which given message replies 提出,但解决方案没有解决问题,我没有必要的声誉在线程中进一步评论。

【问题讨论】:

    标签: python telegram-bot


    【解决方案1】:

    没关系。

    我得到了我缺乏的地方。显然,如果我尝试回复在机器人的隐私设置关闭之前发送的组中的用户消息,我将不会在 Update 对象中获得 reply_to_message 属性。

    有趣的是,我实际上是如何不得不提出一个问题才能最终了解发生了什么。 :)

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 2019-11-27
      • 2018-08-26
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 2021-08-01
      相关资源
      最近更新 更多