【问题标题】:async def on_ready(): SyntaxError: invalid syntaxasync def on_ready(): SyntaxError: 无效语法
【发布时间】:2021-01-17 09:45:56
【问题描述】:

我正在制作一个不和谐的机器人,我是 python 新手,我已经查找但没有找到任何关于如何解决这个问题的答案,但我从这段代码中得到了错误

代码:

import discord
from discord.ext import commands

client = command.Bot(command_prefix="<")

@client.event
async def on_ready():
    print("Bot is online")

@client.command()
synd def Test(ctx):
    await ctx.send("Test successful")

client.run(Token)

有错误的行:

@client.event
async def on_ready():
    print("Bot is online")

错误:

async def on_ready():
    ^
SyntaxError: invalid syntax

有谁知道如何解决这个问题?我正在使用 Python 版本:pip 19.2.3 (python 3.8)

【问题讨论】:

  • 你100%确定你使用的是python3而不是python2吗?

标签: discord.py


【解决方案1】:

已编辑

打印功能需要另外4个空格:

async def on_ready():
        print("Bot is online")

【讨论】:

  • 我尝试安装 asyncio 但它仍然无法正常工作。感谢您告诉我我没有看到我在异步时输入错误
  • 错误很明显,您需要将打印功能再缩进 4 个空格。我编辑了我的答案。看看
【解决方案2】:

你可以尝试使用命令“python3 file_name.py”

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2021-05-09
  • 2021-09-07
  • 2020-03-07
  • 2015-09-08
  • 1970-01-01
  • 2018-08-01
  • 2021-08-30
  • 2013-12-19
相关资源
最近更新 更多