You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Pyrogram/Telethon根据用户ID获取Telegram用户简介

获取Telegram用户简介(Bio)的实现方案

Pyrogram 方法

app.get_chat_members 返回的 User 对象默认不包含简介字段,需通过用户ID单独调用 app.get_users() 获取完整用户信息,该接口会返回带 bio 属性的完整 User 对象。

示例代码:

import asyncio
from pyrogram import Client

# 替换为你的实际参数
api_id = 123456
api_hash = "your_api_hash_here"
TARGET = -1001234567890

app = Client("my_account", api_id=api_id, api_hash=api_hash)

async def main():
    async with app:
        async for member in app.get_chat_members(TARGET):
            # 获取包含简介的完整用户数据
            full_user = await app.get_users(member.user.id)
            print(f"用户ID: {full_user.id}")
            print(f"昵称: {full_user.first_name}")
            print(f"简介: {full_user.bio if full_user.bio else '无简介'}")
            break  # 仅演示第一个成员,移除可遍历全部

app.run(main())

Telethon 方法

Telethon 中可通过 client.get_users() 获取完整用户对象,简介对应属性为 bio。若 iter_participants 返回的对象已包含简介,可直接使用,无需额外调用。

示例代码:

from telethon import TelegramClient
from telethon.tl.types import User

# 替换为你的实际参数
api_id = 123456
api_hash = "your_api_hash_here"
TARGET = -1001234567890

client = TelegramClient("my_account", api_id, api_hash)

async def main():
    async with client:
        async for member in client.iter_participants(TARGET):
            if isinstance(member, User):
                # 获取完整用户信息(按需选择是否调用)
                full_user = await client.get_users(member.id)
                print(f"用户ID: {full_user.id}")
                print(f"昵称: {full_user.first_name}")
                print(f"简介: {full_user.bio if full_user.bio else '无简介'}")
                break  # 仅演示第一个成员,移除可遍历全部

client.start()
client.loop.run_until_complete(main())

注意事项

  • 若用户设置了隐私权限,可能无法获取其简介,返回值为 None,需做空值处理。
  • 确保你的账号/机器人已加入目标群组,且有权限查看群成员信息。

内容的提问来源于stack exchange,提问作者SvatoyDyavol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 21:20:43