【问题标题】:How to write the received id from get_chat_members Pyrogram to a separate file?如何将从 get_chat_members Pyrogram 接收到的 id 写入单独的文件?
【发布时间】:2022-07-04 10:11:21
【问题描述】:

我怎样才能使它在使用 pyrogram 库解析组中的成员时,写入一个单独的文件,只写入用户的 id 或用户名?

我的代码:

from pyrogram import Client

TARGET = -10011796008

app = Client("my_account")

async def main():
    async with app:
        async for member in app.get_chat_members(TARGET, limit=1):

app.run(main())

写入控制台的示例:

{
    "_": "ChatMember",
    "status": "ChatMemberStatus.MEMBER",
    "user": {
        "_": "User",
        "id": 87453014,
        "is_self": false,
        "is_contact": false,
        "is_mutual_contact": false,
        "is_deleted": false,
        "is_bot": false,
        "is_verified": false,
        "is_restricted": false,
        "is_scam": false,
        "is_fake": false,
        "is_support": false,
        "first_name": "Niker",
        "status": "UserStatus.RECENTLY",
        "username": "Zenixex"
    },
    "joined_date": "2022-03-19 23:22:18"`

我需要 "id": 87453014 写入控制台中的单独文件

【问题讨论】:

    标签: python


    【解决方案1】:

    选择一个特定的值:

    b = await app.get_users(chat_id)
    print(f"{b.id} | {b.username}")
    
    
    >>> 13911381 | qwerty123
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多