如何使用 Python-Telegram-Bot 获取 Telegram 用户的用户名、名字或姓氏? [英] How To Obtain Username, First Name Or Last Name Of A Telegram User With Python-Telegram-Bot?

查看:62
本文介绍了如何使用 Python-Telegram-Bot 获取 Telegram 用户的用户名、名字或姓氏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python-Telegram-Bot

我知道 update.message.chat_id 返回用户的聊天 ID,但我需要知道如何获取用户的用户名或名字和/或姓氏.

I Know That update.message.chat_id Returns The User's Chat ID, But I Need To Know How To Get User's Username Or First Name And/Or Last Name.

我在 Telegram 的文档中找到了 这个,但我不知道如何去做使用它(我试过 bot.getChat(update.message.chat_id) 但没有结果)

I've Found This On Telegram's Documentation But I Don't Know How To Use It ( I Tried bot.getChat(update.message.chat_id) But No Result)

推荐答案

关于用户的所有信息(如用户名、ID、名字/姓氏和个人资料照片)可从 telegram.User 对象.您可以使用 telegram.Message

All infomation about user (as username, id, first/last name and profile photos) available from telegram.User object. You can easily get it using telegram.Message

user = update.message.from_user
print('You talk with user {} and his user ID: {} '.format(user['username'], user['id']))

这篇关于如何使用 Python-Telegram-Bot 获取 Telegram 用户的用户名、名字或姓氏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆