1

I don't want to make many request so was wondering if it's possible to create an array of users i intend to push to my telegram group and make a single request.

client(InviteToChannelRequest(target_group,[user_array]))

1 Answers1

0

It already asks for list of users. Normally [user] means single 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())

Simply give it array of users with brackets [,].

Gray Programmerz
  • 479
  • 1
  • 5
  • 22