I want to use Telethon from the django. But when I am running it, I am getting following error:
RuntimeError: There is no current event loop in thread 'Thread-1'.
my code views.py:
from django.shortcuts import render,HttpResponse
from telethon.sync import TelegramClient, events
async def join(client):
ch = '@andeh_ir'
try:
await client(JoinChannelRequest(ch))
print('[+] Joined The Channel')
except:
print('[-] skiped')
def addChannel(request):
api_id = XXXXXX
api_hash = 'xxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('+254716550762', api_id, api_hash )
with client:
client.loop.run_until_complete(join(client))
return HttpResponse('addChannel')
My solution:
import asyncio
api_id = xxxx
api_hash = 'b772662cf8a918bfbc39ee2aee36f6cc'
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
client = TelegramClient(phone, api_id, api_hash, loop=loop)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With