我是编程新手。我试图让我的 discord 机器人打开命令提示符以确认它可以运行,但我收到此错误:
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]
代码:
import discord
from discord.ext import commands
client=commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print('ok')
client.run(token)
是什么原因导致此错误,我该如何解决?
编辑:经过一些测试,我相信“client.run(token)”是导致“事件循环关闭”的原因,不知道为什么。
原文由 yungcoder 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试在开发人员门户上启用意图,当我遇到同样的问题时它对我有用