user14766510
user14766510

Reputation:

discord py - Bot ignores "if" check

I have a weird problem and can't find a solution for it. I want to get the best user from my JSON leaderboard and it's working. But now I want to check if the message.author and the user from the leaderboard have the same User-ID. If yes, then an action should run.

My code:

with open("level.json", "r") as a:
     level = json.load(a)
     high_score_list = sorted(level, key=lambda x: level[x].get('secXP'), reverse=True)
     print(f"User2: {high_score_list[0]} + msg author: {message.author.id} - {message.author.name}")
     # thats not working
     if message.author.id == high_score_list[0]:
        embed.set_author(name=f'best leaderboard user!)
        embed.color = 0x686de0

Even if the User-IDs are the exact same from the if check, the bot doesn't do it. I tried "print" Lines at the if check, but even this is not running.

Upvotes: 0

Views: 50

Answers (1)

Lukas Schmid
Lukas Schmid

Reputation: 1960

I'd assume your issue is with datatypes. Check your json whether the highscorelist has text or number entries. The author's id is always of type int so if your highscore is a string they won't ever be equal.

Upvotes: 1

Related Questions