Я пробовал этот код:
Код: Выделить всё
bot = Bot(token=bot_token)
dp = Dispatcher()
client = TelegramClient("session", api_id, api_hash).start(bot_token=bot_token)
@dp.message(CommandStart())
async def start(message: types.Message):
await message.answer("text aiogram")
await client_send(message)
async def client_send(message: types.Message):
async with client:
await client.send_message(message.chat.id, "text telethon")
async def main():
await dp.start_polling(bot)
if __name__ == '__main__':
asyncio.run(main())
Код: Выделить всё
Cause exception while process update id=xxx by bot id=xxx
RuntimeError: The asyncio event loop must not change after connection (see the FAQ for details)
Traceback (most recent call last):
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "C:\Users\Artyxx\Documents\Python\bot\bot-check-in\testcode.py", line 19, in start
await client_send(message)
File "C:\Users\Artyxx\Documents\Python\bot\bot-check-in\testcode.py", line 23, in client_send
async with client:
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\telethon\client\auth.py", line 657, in __aenter__
return await self.start()
^^^^^^^^^^^^^^^^^^
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\telethon\client\auth.py", line 141, in _start
me = await self.get_me()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\telethon\client\users.py", line 165, in get_me
me = (await self(
^^^^^^^^^^^
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\telethon\client\users.py", line 30, in __call__
return await self._call(self._sender, request, ordered=ordered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Artyxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\telethon\client\users.py", line 34, in _call
raise RuntimeError('The asyncio event loop must not change after connection (see the FAQ for details)')
RuntimeError: The asyncio event loop must not change after connection (see the FAQ for details)
Подробнее здесь: https://stackoverflow.com/questions/790 ... d-telethon