【问题标题】:CallbackQueryHandler reply message instead of edit message - Python Telegram BotCallbackQueryHandler 回复消息而不是编辑消息 - Python Telegram Bot
【发布时间】:2021-12-18 06:05:21
【问题描述】:

我正在使用python telegram bot 开发一个机器人

我希望能够从 InlineKeyboardButton 发送回复消息,而不必编辑当前消息。

def callback(update, context):

    # this works (but I don't want to edit the current message but sending a new one)
    update.callback_query.edit_message_text("response")
    
    # this unfortunately does not work
    update.message.reply_text("response") # None has no attribute 'reply_text'


...


updater.dispatcher.add_handler(CallbackQueryHandler(self.callback))

【问题讨论】:

    标签: python callback bots telegram-bot python-telegram-bot


    【解决方案1】:

    一次只会出现Update 的一个可选属性。如果通过按下内联按钮进行更新,则 update.callback_query 存在,但 update.message 不存在。但是,update.callback_query.message 可能会出现,这取决于带有内联按钮的消息是由机器人本身还是通过内联模式发送的。如果存在,您还可以通过便利属性update.effective_message 访问它。


    免责声明:我目前是python-telegram-bot的维护者

    【讨论】:

    • 就像一个魅力,谢谢:)
    猜你喜欢
    • 2017-08-07
    • 2020-10-04
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    相关资源
    最近更新 更多