首页 > 解决方案 > Telegram API:如何从 id (Python telepot) 获取用户名?

问题描述

我将我的机器人的所有用户的 ID 保存在数据库中,但是如果我知道 ID,如何获取他们当前的用户名?我正在使用 Python 3 和 Telepot 框架。

标签: pythontelegramtelegram-botpython-telegram-bottelepot

解决方案


user_id中的用户信息可以通过 中的getChat方法获取telepot

bot = telepot.Bot(TOKEN)
info = bot.getChat(user_id)
print(info)

推荐阅读