Discord.py:如何修复“事件循环已关闭" [英] Discord.py: How to fix "event loop is closed"

查看:46
本文介绍了Discord.py:如何修复“事件循环已关闭"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.我试图让我的Discord机器人打开命令提示符以确认它可以运行,但出现此错误:

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\---\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)

什么原因导致此错误,该如何解决?

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:如何修复“事件循环已关闭"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆