如何仅使用用户的@handler来获取用户的个人资料图片

问题描述 投票:0回答:1

我有一个用于 Telegram 的 Python 机器人,总而言之,这个想法是,给定包含提及的用户输入,我想获取所提及用户的照片或其 user.id。我有一个适用于没有处理程序的用户的代码,但我想找到一种适用于所有用户的方法。

entities = message.parse_entities()

if not entities:
    return

for entity in entities:
    if entity.type not in {"mention", "text_mention"}:
        continue

    user = entity.user

    if not user:
        print(">>> user not found") # this only happen for who have @username
        continue

    print(">>> user", user.id, user.name) # this works for non @username
python telegram python-telegram-bot
1个回答
0
投票

Bot API 无法将用户名解析为用户 ID。根本不包括此功能。为此你需要一个用户机器人。您可能对

ptbcontrib/username_to_chat_api
感兴趣。


免责声明:我目前是

python-telegram-bot
的维护者。

© www.soinside.com 2019 - 2024. All rights reserved.