Brandon Pardi
Brandon Pardi

Reputation: 246

Python Discord Bot 'Event Loop is Closed'

when I run my Discord bot it connects and get RuntimeError: Event loop is closed. This only occurred recently when I was trying to fix my client events not working, and added intents = discord.Intents().all() and then added that into my client initializer client = commands.Bot(command_prefix = './', intents = intents) The specific event I was working on is an auto role feature. Here are 2 attempts I made at it

@client.event
async def on_member_join(member):
    guild = client.get_guild(528767443653623818)
    channel = client.get_channel(722970243252879420)
    role = guild.get_role(719421779600343110)
    await channel.send(f"Wow, {member} just joined the Pardi!")
    await member.add_roles(role)
    await channel.send(f"{member} is now a {role}")
@client.event
async def on_member_join(member):
    role = get(member.guild.roles, name=ROLE)
    await member.add_roles(role)
    print(f"{member} is now a {role}")

Any help is appreciated :)

EDIT Been asked to post the traceback so here it is

Traceback (most recent call last):
  File "dbot.py", line 184, in <module>
    client.run(token)
  File "C:\Users\Brandon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 708, in run
    return future.result()
  File "C:\Users\Brandon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 687, in runner
    await self.start(*args, **kwargs)
  File "C:\Users\Brandon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 651, in start
    await self.connect(reconnect=reconnect)
  File "C:\Users\Brandon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 586, in connect
    raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go 
to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001CB8B73DF70>
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001CB8B73DF70>
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 719, in call_soon
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 508, in _check_closed
RuntimeError: Event loop is closed

Upvotes: 0

Views: 947

Answers (1)

Arfath Yahiya
Arfath Yahiya

Reputation: 179

As the traceback says it might be error in the token you entered or the intents are not enabled

Sorry couldn't add comment because my reputation is low

Hope it might help if not just ping me up again

Upvotes: 2

Related Questions