create_task = asyncio.async:SyntaxError:语法无效 [英] create_task = asyncio.async: SyntaxError: invalid syntax

查看:381
本文介绍了create_task = asyncio.async:SyntaxError:语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Discord创建一个机器人,我只是编写了以下简单代码:

I'm creating a bot for Discord, and I just wrote this simple code:

import discord

TOKEN = "token"

client = discord.Client()


@client.event
async def on_ready():
    print('Bot is ready.')


client.run(TOKEN)

,它会产生以下错误:

Traceback (most recent call last):
  File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/Main.py", line 1, in <module>
    import discord
  File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/client.py", line 38, in <module>
    from .state import ConnectionState
  File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/state.py", line 36, in <module>
    from . import utils, compat
  File "/Users/pcaires/Desktop/Programação/Python/Discord Bots/venv/lib/python3.7/site-packages/discord/compat.py", line 32
    create_task = asyncio.async
                              ^
SyntaxError: invalid syntax

我搜索了在互联网上,大多数人说使用Python 3.7,这就是我一直在使用的。另外,我一直在使用PyCharm作为Python的IDE。

I searched and searched in the internet, and most of the people say to use Python 3.7, and that's what I've been using. Also, I've been using PyCharm as my IDE for Python.

推荐答案

错误从何而来?



您使用的discord.py版本不支持Python 3.7 (其中 async 变为保留的关键字),如此问题所述。
此版本的discord.py,它是 GitHub存储库上的默认分支,

Where does the error come from?

The version of discord.py you are using does not support Python 3.7 (in which async becomes a reserved keyword), as explained in this issue. This version of discord.py, which is the default branch on the GitHub repo, is sadly the one installed by Pip.

您可以选择:


  • 将您的Python版本降级为3.6。

  • 根据正在重写开发中的分支 ,例如,使用以下命令: python3 -m pip install --user -U https://github.com/ Rapptz / discord.py / archive / rewrite.zip

  • downgrade your version of Python to 3.6.
  • install another version of discord.py, based on the rewrite branch which is under active development, for example with the command : python3 -m pip install --user -U https://github.com/Rapptz/discord.py/archive/rewrite.zip

这篇关于create_task = asyncio.async:SyntaxError:语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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