python 无理由的随机错误

rxztt3cl  于 2022-11-21  发布在  Python
关注(0)|答案(1)|浏览(161)

由于某种原因,我遇到了很多关于缩进的errors。我没有看到任何错误,我已经多次重新键入缩进。也许这与我的另一个问题here?有关
下面是错误所在的代码:

@bot.command(description="See your balance or somebody else's balance.", aliases=['bal'])
async def balance(ctx, member: discord.Member = None):
if member:
    if not currency['balance'][member.id]:
        currency['balance'][member.id] = 0
        save_data()
        ctx.message.reply(embed=discord.Embed(
            title=f"{member.name}'s Balance",
            description=f"{member.name}'s balance is `{currency['balance'][member.id]}`"
        ))
else:
    if not currency['balance'][ctx.author.id]:
        currency['balance'][ctx.author.id] = 0
    ctx.message.reply(embed=discord.Embed(
        title=f"Your Balance",
        description=f"Your balance is `{currency['balance'][ctx.author.id]}`"
    ))
khbbv19g

khbbv19g1#

函数定义之后的所有行都需要再次缩进,因为它们必须属于函数实现。如下所示:

@bot.command(description="See your balance or somebody else's balance.", aliases=['bal'])
async def balance(ctx, member: discord.Member = None):
    if member:
        if not currency['balance'][member.id]:
            currency['balance'][member.id] = 0
            save_data()
            ctx.message.reply(embed=discord.Embed(
                title=f"{member.name}'s Balance",
                description=f"{member.name}'s balance is `{currency['balance'][member.id]}`"
            ))
    else:
        if not currency['balance'][ctx.author.id]:
            currency['balance'][ctx.author.id] = 0
        ctx.message.reply(embed=discord.Embed(
            title=f"Your Balance",
            description=f"Your balance is `{currency['balance'][ctx.author.id]}`"
        ))

相关问题