【发布时间】:2020-07-04 19:12:20
【问题描述】:
我正在使用 discord.py 制作一个不和谐的机器人,并且我正在为我的借用命令使用事件循环,但是当我运行它时,它给了我一堆错误代码。错误代码表示循环已经在运行,但我只是将代码 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
【问题讨论】:
-
@isAif 谢谢,看起来很糟糕。
标签: python discord.py