简体   繁体   中英

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

I'm trying to make my first ever discord bot in pyhton, it's an economy bot but it says that I cannot use the await function and I don't know why.

@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!")

ok, so i see 2 problems. The first one is that the @bot.command has to be aligned with async def and 2nd you have 6 await functions. Please specify which await function is giving you the error.

The Answer was just to align @bot.command and async def

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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