因此,我和一个朋友已经完成了级别排行榜命令。这是代码。
@commands.command()
async def leaderboard(self, ctx):
with open('level.json', 'r') as fp:
users = json.load(fp)
high_score_list = sorted(users, key=lambda x : users[x].get('level', 0), reverse=True)
message = ''
for number, user in enumerate(high_score_list):
message += '{0}. {1} with {2}level\n'.format(number + 1,user, users[user].get('level', 0))
await ctx.send('{}'.format(high_score_list))
但是,令我们惊讶的是,这出现了。
['550912080627236874', '499454400994082826', '578729911284400138', '757122465687273525', '726314322565005382', '472984563447103518', '159985870458322944', '746515506688688178', '733012127576490165', '754945861112430693', '750960499063259196', '359550695042711552', '575252669443211264', '553292456226062367', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
它确实反复出现。 我们如何做到这一点,从而使排行榜形式的名称显示出来?谢谢!