gpt4 book ai didi

discord - create_task = asyncio.async : SyntaxError: invalid syntax

转载 作者:行者123 更新时间:2023-12-02 07:41:33 26 4
gpt4 key购买 nike

我正在为 Discord 创建一个机器人,我刚刚编写了这个简单的代码:

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。

最佳答案

错误从何而来?

您使用的discord.py版本不支持Python 3.7(其中async成为保留关键字),如 this issue 中所述。 。此版本的discord.py,是 GitHub repo 上的默认分支,遗憾的是 Pip 安装的。

如何修复

您可以:

  • 将您的 Python 版本降级至 3.6。
  • 安装另一个版本的discord.py,基于rewrite branch 正在积极开发,例如使用命令:python3 -m pip install --user -U https://github.com/Rapptz/discord.py/archive/rewrite。 zip

关于discord - create_task = asyncio.async : SyntaxError: invalid syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51196568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com