почему возникает подобная ошибка и как её решить, помогите пожалуйста
у меня подобный код:
from telethon.sync import TelegramClient
import telebot
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
import re
import pysqlite3
from telethon.sessions import SQLiteSession
import asyncio
api_id = 28335256
api_hash = 'c7cab7a06357e3b116358aa6d0c75b7c'
phone = '79935535061'
target_group = None
session_file = '79935535061.session'
session = SQLiteSession(session_file)
client = TelegramClient(session, api_id, api_hash)
bot = telebot.TeleBot("6107982583:AAGrjbdfSazg9W8mYEckyIS_RFtf3258xAU")
client.start()
async def get_participants(link):
entities = await client.get_entity(link)
participants = await client(GetParticipantsRequest(
entities,
ChannelParticipantsSearch(''),
200
))
return participants.users
@bot.message_handler(commands=['start', 'parse'])
def work_parse(message):
bot.send_message(message.chat.id, "Введите ссылку на телеграм-чат:")
@bot.message_handler(func=lambda message: True)
def handle_all_messages(message):
asyncio.ensure_future(work_parse(message)) # запустим работу в асинхронном режиме
async def work_parse(message):
global target_group
target_group = message.text
await bot.send_message(message.chat.id, "Производится парсинг...")
participants = await get_participants(target_group)
phone_regex = re.compile(r"\+?\{7,16}")
for user in participants:
if user.phone:
phone = re.findall(phone_regex, user.phone)[0]
print(phone)
target_group = None
async def main():
bot_pooling = asyncio.create_task(bot.polling(none_stop=True))
await bot_pooling
await asyncio.wait([work_parse(message)])
asyncio.run(main())
и возникает следующая ошибка:
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'WorkerThread1'.
пробовал уже кучу вариантов, но не помогает, подскажите пожалуйста что делать
Источник: Stack Overflow на русском