簡體   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