Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SyntaxError:';等待&x27;外部函数,即使它位于异步_Python_Discord_Discord.py - Fatal编程技术网

Python SyntaxError:';等待&x27;外部函数,即使它位于异步

Python SyntaxError:';等待&x27;外部函数,即使它位于异步,python,discord,discord.py,Python,Discord,Discord.py,我正在尝试在Pyton制作我的第一个discord机器人,它是一个经济型机器人,但它说我不能使用等待功能,我不知道为什么 @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

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

@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!")
@bot.command()
异步def提取(ctx,金额=无):
等待开户(ctx.author)
如果金额==无:
等待ctx.send(“请输入有效金额”)
返回
bal=等待更新银行(ctx.author)
金额=整数(金额)
如果金额>余额[1]:
等待ctx。发送(“你没有足够的土豆!”)
返回

如果数量正常,那么我看到两个问题。第一个是
@bot.command
必须与
async def
对齐,第二个是有6个等待函数。请指定哪个等待函数会给您错误。

好的,因此我看到两个问题。第一个是
@bot.command
必须与
async def
对齐,第二个是有6个等待函数。请指定给您错误的等待函数。

答案是对齐
@bot.command
异步定义
答案是对齐
@bot.command
异步定义

如果不一致。重写,则不使用异步,或者确保您使用的是正确的python版本。如果这是discord.rewrited,则不要使用async,或者确保您使用的是正确的python版本。并且,可能是为了纠正其余的缩进问题。您不能在
async def…
函数之外使用
await()
。您从
bal=await update\u bank(ctx.author)
(完全没有缩进)开始的行不在函数范围内,因此这六个等待抛出了编译错误。请单击我答案上的复选标记,以便此问题有一个答案,大概是为了更正其余缩进问题。您不能在
async def…
函数之外使用
await()
。您从
bal=await update\u bank(ctx.author)
(完全没有缩进)开始的行不在函数范围内,因此这六个等待抛出编译错误。请单击我答案上的复选标记,以便此问题有答案