'Name repeats in leaderboard discord.py
I've made a simple points bot for discord with a leaderboard. The problem is that if any two users have the same number of points, the name is repeated twice on the leaderboard. I know why the problem is occurring but cannot think up of a way to stop it
@commands.has_permissions(manage_roles=True)
async def leaderboard(doc,x=5):
with open("playerdb.json","r") as db:
info=json.load(db)
leader_board={}
total=[]
for mem in info:
name=int(mem)
amount=info[str(mem)]["points"]
leader_board[amount]=name
total.append(amount)
total=sorted(total,reverse=True)
embed=discord.Embed(title=f"Top {x} Members With Highest Points Are",color=0x7289da)
index=1
for points in total:
id_=leader_board[points]
mems=discord.utils.get(doc.guild.members,id=id_)
name=mems.name
embed.add_field(name=f"{index}. {name}",value=f"{points}",inline=False)
if index==x:
break
else:
index += 1
await doc.send(embed=embed)```
Solution 1:[1]
i think you don't have all the intents on?
<p><strong>NOTE: Once your bot reaches 100 or more servers, this will require verification and approval. <a href="https://support.discord.com/hc/en-us/articles/360040720412" target="_blank" rel="noreferrer">Read more here</a></strong></p>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | H1387XD |