【问题标题】:Is it possible to pass array containing userids to add to telegram group in single request?是否可以在单个请求中传递包含用户 ID 的数组以添加到电报组?
【发布时间】:2022-01-15 02:23:41
【问题描述】:

我不想提出很多请求,所以想知道是否可以创建一组我打算推送到我的电报组并发出单个请求的用户。

client(InviteToChannelRequest(target_group,[user_array]))

【问题讨论】:

    标签: python telegram telegram-bot telethon


    【解决方案1】:

    它已经要求提供用户列表。通常[user] 表示单个用户。

    from telethon import TelegramClient
    from telethon.tl.functions.channels import InviteToChannelRequest
     
    import asyncio
    
    async def main():
        api_id = 0989567                                             # TODO: insert your api id
        api_hash = '0985583654b679215bfe3a8205678098'                # TODO: insert your api hash
        phone = '913097809782'                                       # TODO: insert your phone number
        IDs = ["username1","username2"]                              # TODO: insert username of folks
        target_group = await client.get_input_entity(-1001155998262) # TODO: insert group/channel id here
        users = []
        async with TelegramClient(phone, api_id, api_hash) as client:
            for ID in IDs:
                users.append(await client.get_input_entity(ID))
            await client(InviteToChannelRequest(target_group, users))
    
    asyncio.run(main())
    

    只需用括号[,] 给它用户数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-02
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多