【问题标题】:Get user id and user name from balebot [closed]从balebot获取用户ID和用户名[关闭]
【发布时间】:2018-05-05 13:01:07
【问题描述】:

请解释如何获取在balebot中与我的机器人交谈的客户的user.id和user.name。有一个peer class,但我不知道它是如何工作的?

【问题讨论】:

  • 请在 Meysam 此处发布您的代码,以便我们为您提供帮助!

标签: python python-3.x messenger


【解决方案1】:

它是一种使用get_effective_user()函数获取peer_id或accesshash的简单方法,见:

user_peer=update.get_effective_user()
user_id = user_peer.peer_id

但如果您需要更多信息,您可以从更新 Json 中获取用户名和其他字段。像这样:

def text_received(bot, update):
        for user in update.users:
            print(user.get_json_object())
            ....

【讨论】:

    猜你喜欢
    • 2019-12-30
    • 2021-07-18
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 2016-04-27
    • 1970-01-01
    相关资源
    最近更新 更多