[英]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.我正在尝试在 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!")
ok, so i see 2 problems.好的,所以我看到了 2 个问题。 The first one is that the @bot.command
has to be aligned with async def
and 2nd you have 6 await functions.第一个是@bot.command
必须与async def
对齐,第二个是你有 6 个 await 函数。 Please specify which await function is giving you the error.请指定哪个 await function 给您错误。
The Answer was just to align @bot.command
and async def
答案只是对齐@bot.command
和async def
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.