'Python Discord: RuntimeError: Event loop is closed when launched from a specific network
RuntimeError: Event loop is closed
error when trying to run any bot in discord when connected to my wifi network. When connected to another network, everything works as it should.
Code example:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
bot.run(TOKEN)
I am getting the above error when trying to run this code. I am accurately passing the correct access token and have all intents enabled:
I'm using py-cord
, but the problem also occurred when using the discord-py
library.
I have the latest version of py-cord==2.0.0b7
installed using the command
pip install git+https://github.com/Pycord-Development/pycord
Full text of the error:
Traceback (most recent call last):
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 550, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py", line 483, in wait_for
return fut.result()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 330, in from_client
socket = await client.http.ws_connect(gateway)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 214, in ws_connect
return await self.__session.ws_connect(url, **kwargs)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client.py", line 769, in _ws_connect
raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 503, message='Invalid response status', url=URL('wss://gateway.discord.gg/?encoding=json&v=10&compress=zlib-stream')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PythonCode.py", line 11, in <module>
bot.run(TOKEN)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 715, in run
return future.result()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 694, in runner
await self.start(*args, **kwargs)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 658, in start
await self.connect(reconnect=reconnect)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 610, in connect
ws_params.update(sequence=self.ws.sequence, resume=True, session=self.ws.session_id)
AttributeError: 'NoneType' object has no attribute 'sequence'
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000173E3CD74C0>
Traceback (most recent call last):
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Solution 1:[1]
If the problem occurs only in a specific Wi-Fi network, it is probably worth trying to restart the router - this was the solution to the problem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | denisnumb |