Discord API在尝试导入时出现错误 [英] Discord API giving errors when trying to import it

查看:167
本文介绍了Discord API在尝试导入时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试安装Discord API并正常工作,但我一生都无法弄清楚该怎么做。

I've been trying to get the Discord API installed and working but I can't for the life of me figure out how.

我尝试的第一件事就是使用
py -m pip install discord
来简单地安装Discord API。它安装了,但是当我导入它时,出现了这个错误

The first thing I tried was to simply install the Discord API using py -m pip install discord It installed but when I imported it, I got this error

File "<stdin>", line 1, in <module>
  File "C:\Users\Harry\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\Harry\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 38, in <module>
    from .state import ConnectionState
  File "C:\Users\Harry\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\state.py", line 36, in <module>
    from . import utils, compat
  File "C:\Users\Harry\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\compat.py", line 32
    create_task = asyncio.async
                              ^
SyntaxError: invalid syntax

我后来发现这是由Discord API的较旧版本引起的错误,因此我尝试使用 py -m pip install --upgrade discord
似乎工作正常,但导入库时仍然出现相同的错误

I later found out that this was an error caused by an older version of the Discord API, so I tried to upgrade it using py -m pip install --upgrade discord It seemed to work fine but I still got the same error when importing the library

所以我接下来要尝试的是卸载Discord API并重新安装。但是当我尝试重新安装它时,它说它已经安装了。

So the next thing I tried was to uninstall the Discord API and reinstalling it. But when I tried to re-install it, it said it was already installed.

因此,我手动进入Lib\site-packages文件夹并删除了这两个文件夹。尽管如此,当尝试安装它时,什么也没有。仍然说它已经安装了。

So I manually went into the Lib\site-packages folder and deleted both folders. Still, when trying to install it, nothing. Still said it was installed.

我什至完全重新安装了Python,而Python仍然说安装了Discord。

I even re-installed Python entirely, and Python still said that Discord was installed.

在导入Discord时,我仍然遇到相同的错误。

And I still got the same error while importing Discord.

在这一点上,我对如何使其正常工作一无所知。

I am honestly clueless at this point on how to get it working. Any help would be very much appreciated.

推荐答案

Discord-py的当前发行版与Python 3.7不兼容,请参见例如。 此GitHub问题

作者建议切换到库的 rewrite 版本

The current release version of Discord-py is not compatible with Python 3.7, see e.g. this GitHub issue.
The authors suggest switching to the rewrite version of the library.

如果您想尝试这样做,

python -m pip install -U https://github.com/Rapptz/discord.py/archive/rewrite.zip#egg=discord.py[voice]

应该起作用。您也可以只使用Python 3.6而不是3.7。

should work. You can also just use Python 3.6 instead of 3.7.

这篇关于Discord API在尝试导入时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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