【问题标题】:top coins with i\use of tabs and spaces error in discord.py在 discord.py 中使用制表符和空格错误的顶级硬币
【发布时间】:2021-07-25 18:06:29
【问题描述】:

我尝试在硬币上做顶,但标签有错误,代码看起来不错...

我的代码:

@bot.command()
async def list(ctx):
    if ctx.author.guild_permissions.administrator:
        with open('coins.json', 'r') as f:
            users = json.load(f)
        leader_board = {}
        total = []
        for member in users:
            name = int(member)
            xp = users[str(member)]['coins']
            leader_board[xp] = name
            total.append(xp)

        total = sorted(total, reverse=True)

        embed = discord.Embed(title=f"Top 10", color=random.choice(colors))
        index = 1
        for xp in total:
            id_ = leader_board[xp]
            member = await bot.fetch_user(id_)
            name = member.name
            embed.add_field(name=f"{index}. {name}", value=f"{round(xp)} Coins",  inline=False)
            if index == 10:
                break
            else:
                index += 1
        await ctx.send(embed=embed)
    else:
        chat = ctx.channel
        if chat.id == 868869373383811102:
            with open('coins.json', 'r') as f:
                users = json.load(f)
            leader_board = {}
            total = []
            for member in users:
                name = int(member)
                xp = users[str(member)]['coins']
                leader_board[xp] = name
                total.append(xp)

            total = sorted(total, reverse=True)

            embed = discord.Embed(title=f"Top 10", color=random.choice(colors))
            index = 1
            for xp in total:
                id_ = leader_board[xp]
                member = await bot.fetch_user(id_)
                name = member.name
                embed.add_field(name=f"{index}. {name}", value=f"{round(xp)} Coins",  inline=False)
                if index == 10:
                    break
                else:
                    index += 1
            await ctx.send(embed=embed)
        else:
            if chat.id != 868869373383811102:
                bob = await ctx.send("NOPE")
                await time.sleep(5)
                await bob.delete() 

错误: 文件“/home/container/main.py”,第 442 行 bob = 等待 ctx.send("NOPE") ^ TabError:缩进中制表符和空格的使用不一致

它的 3.8 蟒蛇

【问题讨论】:

  • 尝试在第 442 行取消缩进,然后使用最初缩进代码的任何内容(制表符或空格,不能同时使用)再次缩进

标签: python discord.py system


【解决方案1】:

尝试在第 442 行取消缩进该块,然后使用最初用于缩进代码的任何内容再次缩进它(制表符或空格,不能同时使用两者) 如果你使用的是 replit 之类的东西,它们会有错误,有时代码无法正常工作,这就是为什么我建议使用你的电脑来运行代码。

【讨论】:

    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 2011-03-28
    • 2020-08-10
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2015-01-11
    • 2011-10-06
    相关资源
    最近更新 更多