Discord.py RuntimeError: Event loop is closed

Code:

import discord
from discord.ext import commands 

        
client = commands.Bot(command_prefix = 'x')
    
@client.event
async def on_ready():
  print('the bot has logged in successfuly')
    
client.run('lYjCNnKAItxkmQRW******8Cs')

(I replaced some token chars with “” for privacy)*

Erro:

    await self.start(*args, **kwargs)
  File "C:UserspcAppDataLocalProgramsPythonPython39Libsite-packagesdiscordclient.py", line 665, in start
    await self.login(*args, bot=bot)
  File "C:UserspcAppDataLocalProgramsPythonPython39Libsite-packagesdiscordclient.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:UserspcAppDataLocalProgramsPythonPython39Libsite-packagesdiscordhttp.py", line 304, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000289BCCAC790>
Traceback (most recent call last):
  File "C:UserspcAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 116, in __del__
    self.close()
  File "C:UserspcAppDataLocalProgramsPythonPython39libasyncioproactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:UserspcAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 746, in call_soon
    self._check_closed()
  File "C:UserspcAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

What causes this error and how can I resolve it?

Answer

import discord
from discord.ext import commands 
client = commands.Bot(command_prefix = 'x')

@client.event
async def on_ready():
  print('the bot has logged in successfuly')

client.run('lYjCNnKAItxkmQRW******8Cs')

The “B” in “Bot” needs to be capital. And also check the indentation. The first two lines are not properly indented in your question.