Discord.py 运行时错误:事件循环已关闭

时间:2021-04-18 11:11:06

标签: python discord.py

代码:

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')

(为了隐私,我用“”替换了一些标记字符)*

错误:

    await self.start(*args, **kwargs)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\Lib\site-packages\discord\client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\Lib\site-packages\discord\client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\Lib\site-packages\discord\http.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:\Users\pc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

是什么导致了这个错误,我该如何解决?

1 个答案:

答案 0 :(得分:0)

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')

“Bot”中的“B”需要大写。还要检查缩进。您的问题中的前两行没有正确缩进。