[英]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.command
和async def
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.