最近我创建了这个排行榜(下)
但是现在。我将如何使用以下代码创建全球排行榜!
谢谢!
@client.command(aliases = ["lb"])
async def leaderboard(ctx,x: int = 10):
users = await get_bank_data()
leader_board = {}
total = []
for user in users:
name = int(user)
total_amount = users[user]["wallet"] + users[user]["bank"]
leader_board[total_amount] = name
total.append(total_amount)
total = sorted(total, reverse=True)
em = discord.Embed(title=f"Top {x} Richest People", color=random.randint(0, 0xffffff))
index = 1
for amt in total:
id_ = leader_board[amt]
member = await ctx.guild.fetch_member(id_)
if member is None:
raise ValueError(f"Member with id {id_} not found")
name = member.name
em.add_field(name=f"{index}. {name}", value=f"{amt}", inline=False)
if index == x:
break
else:
index += 1
await ctx.send(embed=em)