如何使用replit db使用discord.py创建排行榜命令

2024-09-28 22:28:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道这个代码有什么问题。我没有成功,我是从Github获得的,它总是输出相同的用户。我找了Python Discord的人帮忙。他们无法测试,但最终得到:

@bot.command(name="leaderboard", brief="richest users list", description="list all of the richest users from richest to poorest.")
async def leaderboard(ctx):
    users = db.keys()
    total = {}

    for user in users:
      total[user] += db[f"{user}"]
    
    total = sorted(total.items(), key=lambda x: x[1], reverse=True)
    await ctx.send("the top 5 richest users are...")

    for count, amt in enumerate(total, start=1):
        await ctx.send(f"{count}. {amt} {total[amt]}")

我不知道发生了什么,为什么它没有输出任何东西。请帮忙


Tags: theinsendfordbcountawaitusers