Search code examples
pythonpython-3.xmessenger

Get user id and user name from balebot


Please explain how to get user.id and user.name of client who talking with my bot in balebot. There is a peer class, but i don't know how exactly it works?


Solution

  • its a simple way to use get_effective_user() function to get peer_id or accesshash, see:

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

    But if you need more you can get name and other feilds of user from an Update Json. like this :

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