1

I am creating an application in python and i need to create channel with telegram, for make this, i use telethon:

async def createChannel(username, desc):
try:
    chn = await client(CreateChannelRequest(username,desc,megagroup=False))
    new_channel_id = chn.chats[0].id
    new_channel_access_hash = chn.chats[0].access_hash
    update_response = await client(UpdateUsernameRequest(
            InputPeerChannel(channel_id=new_channel_id,
                            access_hash=new_channel_access_hash), username))
except:
    await client.connect()
    chn = await client(CreateChannelRequest(username,desc,megagroup=False))
    new_channel_id = chn.chats[0].id
    new_channel_access_hash = chn.chats[0].access_hash
    update_response = await client(UpdateUsernameRequest(
            InputPeerChannel(channel_id=new_channel_id,
                            access_hash=new_channel_access_hash), username))
return update_response

I want to use multi threading but when i do that, i got error that say me "No event loop in the thread", so ask google and he gave me this:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

But when i have this and my multi threading, it just stuck and do nothing at this line:

chn = await client(CreateChannelRequest(username,desc,megagroup=False))

Any idea? thx :)

1 Answer 1

1

When initializing the client object, you should pass the event loop to TelegramClient like:

from telethon import TelegramClient

loop = asyncio.new_event_loop()
client = TelegramClient(..., loop=loop)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.