Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py: How to fix "event loop is closed"

I am new to programming. I am trying to have my discord bot open up command prompt to confirm it can run, but I am getting this error:

  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
[Finished in 0.871s]

Code:

import discord
from discord.ext import commands

client=commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    print('ok')

client.run(token)

What causes this error, and how can I fix this?

Edit: after some testing, I believe "client.run(token)" is what is causing "event loop is closed", not sure why.

like image 849
yungcoder Avatar asked Jun 12 '20 08:06

yungcoder


People also ask

Is discord.py getting discontinued?

Discord py is getting discontinued because Discord implemented more and more restrictions for Bot Developers, promised easy verification steps but is behind verification processes by months. Yet introducing more restrictions and now requiring even ID copies.

How do I open a .py Discord bot?

There are two key steps when you're creating a bot: Create the bot user on Discord and register it with a guild. Write code that uses Discord's APIs and implements your bot's behaviors.


2 Answers

I guess your bot has no function, so it just starts and then shuts down again, but I'm not sure. You would have to test this out by for example adding async def on_message(message).

Normally the Event loop is closed "Error" is caused by client.close() or client.logout()

like image 63
FlexGames Avatar answered Oct 22 '22 19:10

FlexGames


try enabling intents on the developer portal it worked for me when i had the same problem

like image 2
idk Avatar answered Oct 22 '22 19:10

idk