我想使用django中的Telethon。但是当我运行它时,我收到以下错误:
RuntimeError:线程“Thread-1”中没有当前事件循环。
我的代码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')
Run Code Online (Sandbox Code Playgroud)