Discord.py:如何修复“事件循环已关闭";
- 作者: 三硝a基甲苯
- 来源: 51数据库
- 2023-02-10
问题描述
我是编程新手.我正在尝试让我的不和谐机器人打开命令提示符以确认它可以运行,但我收到此错误:
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---AppDataLocalProgramsPythonPython38-32libasyncioproactor_events.py", line 116, in __del__ self.close() File "C:Users---AppDataLocalProgramsPythonPython38-32libasyncioproactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:Users---AppDataLocalProgramsPythonPython38-32libasyncioase_events.py", line 719, in call_soon self._check_closed() File "C:Users---AppDataLocalProgramsPythonPython38-32libasyncioase_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)
是什么导致了这个错误,我该如何解决这个问题?
What causes this error, and how can I fix this?
经过一些测试,我相信client.run(token)"是导致事件循环关闭"的原因,不知道为什么.
after some testing, I believe "client.run(token)" is what is causing "event loop is closed", not sure why.
推荐答案
我猜你的机器人没有功能,所以它只是启动然后关闭 再次,但我不确定.您必须通过例如添加 async def on_message(message) 来测试这一点.
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).
通常事件循环是关闭的由 client.close() 或 client.logout()
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0