无法关闭正在运行的事件循环。不和谐的机器人创作 [英] Cannot close a running event loop. Discord bot creation

查看:122
本文介绍了无法关闭正在运行的事件循环。不和谐的机器人创作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一些不同的代码,但是它们似乎都给了我相同的错误。

I tried a few different codes but they all seem to be giving me the same error.

import discord

client = discord.Client()
client.run("TheBotTokenzzzInQuotes")

这给了我这个错误

File "<ipython-input-1-1f31c2ad1160>", line 1, in <module>
    runfile('C:/Users/Lenovo/Desktop/bot.py', wdir='C:/Users/Lenovo/Desktop')

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
        execfile(filename, namespace)

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)

      File "C:/Users/Lenovo/Desktop/bot.py", line 4, in <module>
        client.run("token")

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\discord\client.py", line 637, in run
        _cleanup_loop(loop)

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\discord\client.py", line 97, in _cleanup_loop
        loop.close()

      File "C:\Users\Lenovo\Anaconda3\lib\asyncio\selector_events.py", line 83, in close
        raise RuntimeError("Cannot close a running event loop")

    RuntimeError: Cannot close a running event loop


推荐答案

我有一个自己运行的discord机器人,而我的客户端变量看起来并不像这样

I have my own discord bot that I run, and the client variable for mine doesn't look anything like that if I'm being honest.

如果您 不是 使用 Discord.py Rewrite,则可能失败的原因。

If you are not using "Discord.py Rewrite", that could be a possible reason for a failure.

另一个可能的原因(尽管可能性很小)是您没有安装aiohttp(这是因为吊销asyncio需要Discord.py Rewrite),则可以使用以下命令进行安装:

Another possible reason(although very unlikely) is that you do not have aiohttp installed(which is the dependency asyncio needs for Discord.py Rewrite), you can install it by using the following command:

pip install aiohttp

如果您想看一个示例机器人,我在下面列出了一个直接来自discord.py Rewrite(当前受python支持的版本)开发人员的机器人。

If you would like an example bot to look at, I have listed one below that is directly from the developer of discord.py Rewrite(the version that is currently supported for python).

https://github.com /Rapptz/discord.py/blob/master/examples/basic_bot.py

如果您想知道我的代码开头是什么样,我可以在下面找到它:

If you were wondering what the beginning of my code looked like, I have it below this:

import discord
from discord.ext import commands
from discord.utils import get

client = commands.Bot(command_prefix = '>')

这篇关于无法关闭正在运行的事件循环。不和谐的机器人创作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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