gpt4 book ai didi

python - Discord.py:如何修复 "event loop is closed"

转载 作者:行者123 更新时间:2023-12-03 14:53:10 27 4
gpt4 key购买 nike

我是编程新手。我试图让我的不和谐机器人打开命令提示符以确认它可以运行,但我收到此错误:

  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)”是导致“事件循环关闭”的原因,不知道为什么。

最佳答案

我猜你的机器人没有 function ,所以它只是 开始 然后 关闭 再次,但我不确定。您必须通过例如添加 async def on_message(message) 来测试这一点。 .
通常是 Event loop is closed “错误”是由 client.close() 引起的或 client.logout()

关于python - Discord.py:如何修复 "event loop is closed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62340248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com