Python 电报机器人.获取给定消息回复的消息 [英] Python Telegram Bot. Get message to which given message replies
问题描述
我想开发一个 Telegram 机器人,作为书签系统.它应该处理回复其他消息的命令.实例:
I want to develop a Telegram bot, that acts as a bookmarking system. It should process commands that reply to other messages. The instance:
我使用 python-telegram-bot
进行开发,似乎没有办法看到 /important
回复的消息.我找到了 Update.message.reply_to_message
对象,它仅在用户回复来自机器人本身的消息时才起作用.
I use python-telegram-bot
for development and it seems that there is no way to see that message to which /important
replies. I found the Update.message.reply_to_message
object, which works only when a user replies to a message from the bot itself.
def important_handler(update: Update, context: CallbackContext):
reply_to_message = update.message.reply_to_message
if reply_to_message is None:
logger.error('reply_to_message is None. But it shouldn\'t.')
update.message.reply_text('There is no message attached. Try again.')
return
# ... business logic
有没有办法获得所有回复的 reply_to_message
属性(或替代方法)?感谢您的建议;)
Is there any way to get reply_to_message
attribute (or an alternative) for all the replies? Thanks in advice;)
推荐答案
我遇到了同样的问题.它仅在用户回复机器人时才起作用.我的问题是机器人启用了隐私模式.一旦我通过 /setprivacy
使用 Botfather 禁用它,然后它就起作用了.
I had the same problem. It only worked when a user replied to the bot. My issue was that the bot had Privacy Mode enabled. Once I disabled it with Botfather via /setprivacy
and then it worked.
这篇关于Python 电报机器人.获取给定消息回复的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!