CallbackQueryHandler 回复消息而不是编辑消息 - Python Telegram Bot

CallbackQueryHandler reply message instead of edit message - Python Telegram Bot

我正在使用 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))

只是Update will be present at a time. If the update from pressing an inline button, then update.callback_query is present, but update.message is not. However, update.callback_query.message may be present, depending on whether or not the message with the inline button was sent by the bot itself or via inline mode. If it is present, you can also access it via the convenience property update.effective_message的可选属性之一。


免责声明:我目前是 python-telegram-bot

的维护者