【问题标题】:How to track when user kicked Telegram Bot using python-telegram-bot (Bot API 5.1)如何使用 python-telegram-bot (Bot API 5.1) 跟踪用户何时踢出 Telegram Bot
【发布时间】:2021-04-06 09:49:11
【问题描述】:

Telegram introduced Bot API 5.1ChatMemberUpdated 以及 Update 类中的 my_chat_memberchat_member 字段。

但是如果我正在使用 ConversationHandler,如何跟踪用户现在停止机器人的时间?

以前,我的机器人正在等待 /cancel/stop 等命令。

conversation_handler = ConversationHandler(
    entry_points=...,
    states=...,
    fallbacks=[
        # ...
        MessageHandler(Filters.regex('^/(cancel|stop)$'), flow_stop_chat),
        # ...
    ],
    allow_reentry=True,
    name=current_bot_label,
    persistent=True,
)

现在如何使用 ChatMemberUpdated 正确执行此操作?

【问题讨论】:

    标签: telegram telegram-bot python-telegram-bot


    【解决方案1】:

    使用ChatMemberHandler(PTB v13.4 中的新功能)获取更新并检查update.my_chat_member.new_chat_member.status 以查看您的机器人是否被阻止。但是阻止机器人与简单地发送/cancel 命令并不完全相同,所以我建议保留MessageHandler(或者更好的是,将其更改为CommandHandler(['cancel', 'stop'], flow_stop_chat)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 2018-03-12
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 2021-11-26
      相关资源
      最近更新 更多