我正在使用discord.py制作一个discord机器人,并且在我的借用命令中使用了事件循环,但是当我运行它时,它会给我很多错误代码。错误代码表示循环已在运行,但是我只是对代码进行了bot处理。
注意:discord.py软件包有问题,而不是python本身。
代码:
@tasks.loop(hours=24.0)
async def debt_increase():
for user in coins.keys():
setdebt(user, getdebt(user)+(0.06*getdebt(user)))
async def run_bot():
await client.run(Token)
debt_increase.start()
asyncio.get_event_loop().run_until_complete(run_bot())
错误代码:
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 631, in run
loop.run_forever()
File "/usr/lib/python3.8/asyncio/base_events.py", line 560, in run_forever
self._check_running()
File "/usr/lib/python3.8/asyncio/base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 92, in _cleanup_loop
_cancel_tasks(loop)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 77, in _cancel_tasks
loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
File "/usr/lib/python3.8/asyncio/base_events.py", line 592, in run_until_complete
self._check_running()
File "/usr/lib/python3.8/asyncio/base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 801, in <module>
asyncio.get_event_loop().run_until_complete(run_bot())
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "main.py", line 798, in run_bot
await client.run(Token)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 637, in run
_cleanup_loop(loop)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 97, in _cleanup_loop
loop.close()
File "/usr/lib/python3.8/asyncio/unix_events.py", line 58, in close
super().close()
File "/usr/lib/python3.8/asyncio/selector_events.py", line 89, in close
raise RuntimeError("Cannot close a running event loop")
RuntimeError: Cannot close a running event loop