问题
I've been trying to get the Discord API installed and working but I can't for the life of me figure out how.
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
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
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.
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.
I even re-installed Python entirely, and Python still said that Discord was installed.
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.
回答1:
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.
If you want to try that,
python -m pip install -U https://github.com/Rapptz/discord.py/archive/rewrite.zip#egg=discord.py[voice]
should work. You can also just use Python 3.6 instead of 3.7.
来源:https://stackoverflow.com/questions/52852301/discord-api-giving-errors-when-trying-to-import-it