問題描述
我是編程新手.我正在嘗試讓我的不和諧機器人打開命令提示符以確認它可以運行,但我收到此錯誤:
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:如何修復“事件循環已關閉";的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!