dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
684 stars 162 forks source link

Runtime: Event loop is closed #111

Closed arfathyahiya closed 2 years ago

arfathyahiya commented 2 years ago

Summary

await bot.close() returns Runtime error

Reproduction Steps

just logging out of the bot on windows platform

Code

async def on_connect(self):
        print("Bot Connected")
        await self.get_channel(self.CHANNEL_ID).send("Welp")
        await self.logout()

Expected Results

Exit the event loop quietly without any errors

Actual Results

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000014D19B61280>
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000014D18E1FC10>
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\Python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

System Information

Checklist

Additional Information

I also tried this solution but got the following error

Traceback (most recent call last):
  File "D:/Upwork/Corey Lawson/launcher.py", line 3, in <module>
    bot("NzU3NDU3OTUwMjM4NTcyNTU0.X9WMmA.RHwkoMlsuEESHGH98uLJNQHmIpM", 756281213282680844).run()
  File "D:\Upwork\Corey Lawson\lib\bot\__init__.py", line 28, in run
    super().run(self.TOKEN, reconnect=True)
  File "C:\Users\arfatha\.virtualenvs\Discord Bot Mehmat\lib\site-packages\discord\client.py", line 603, in run
    loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
AttributeError: 'WindowsSelectorEventLoopPolicy' object has no attribute 'add_signal_handler'
arfathyahiya commented 2 years ago

UPDATE:

self.loop = asyncio.WindowsSelectorEventLoopPolicy().get_event_loop()
super().__init__(command_prefix=self.PREFIX, strip_after_prefix=True, case_insensitive=True, loop=self.loop)

This worked for me but now, When trying to await self.wait_until_ready() I get the following error

Traceback (most recent call last):
  File "C:\Users\arfatha\.virtualenvs\Discord Bot Mehmat\lib\site-packages\discord\client.py", line 301, in _run_event
    await coro(*args, **kwargs)
  File "D:\Upwork\Corey Lawson\lib\bot\__init__.py", line 34, in on_connect
    await self.wait_until_ready()
  File "C:\Users\arfatha\.virtualenvs\Discord Bot Mehmat\lib\site-packages\discord\client.py", line 790, in wait_until_ready
    await self._ready.wait()
  File "C:\Users\arfatha\AppData\Local\Programs\Python\Python38\lib\asyncio\locks.py", line 309, in wait
    await fut
RuntimeError: Task <ClientEventTask state=pending event=on_connect coro=<bound method Bot.on_connect of <lib.bot.Bot object at 0x000001E410523790>>> got Future <Future pending> attached to a different loop
dolfies commented 2 years ago

Try updating to python 3.9.

dolfies commented 2 years ago

This has gone stale and isn't something I can resolve in the library. Closing.