Discord Python异步事件循环已关闭

时间:2020-08-19 12:01:09

标签: python asynchronous async-await discord.py

程序结束时出现以下错误。

错误:

RuntimeError: Event loop is closed

代码:

    client = discord.Client()
@client.event
async def on_ready():
    amount2 = 0
    for guild in client.guilds:
        for member in guild.members:
            members.insert(amount2, member)  # or do whatever you wish with the member detail
            amount2 = amount2 + 1
    await client.close()
client.run(TOKEN)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误,并注意到在调试时不会发生,因此我在close调用之后添加了sleep(1):

await client.close()
time.sleep(1)