繁体   English   中英

SyntaxError: 'await' 在 function 之外,即使它在异步内部

[英]SyntaxError: 'await' outside function even tho it is inside a async

我正在尝试在 pyhton 中制作我的第一个 discord 机器人,它是一个经济型机器人,但它说我不能使用等待 function,我不知道为什么。

@bot.command()
async def withdraw(ctx,amount = None):
    await open_account(ctx.author)

  if amount == None:
      await ctx.send("Please enter a valid amount")
      return
  
bal = await update_bank(ctx.author)

amount = int(amount)
if amount>bal[1]:
    await ctx.send("You don't have enough potatoes!")
    return
if amount<0:
    await ctx.send("Can only send positive potatoes! No negative!")
    return

await update_bank(ctx.author,amount)
await update_bank(ctx.author,-1*amount, "bank")

await ctx.send(f"You withdrew {amount} potatoes!")

好的,所以我看到了 2 个问题。 第一个是@bot.command必须与async def对齐,第二个是你有 6 个 await 函数。 请指定哪个 await function 给您错误。

答案只是对齐@bot.commandasync def

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM