Skip to content Skip to sidebar Skip to footer

Economy Bot | Discord.py Rewrite | Leaderboard Error - Attributeerror: 'nonetype' Object Has No Attribute 'name'

I am working on a discord.py economy bot I just get this error. I try this -----> Discord.py get_user(id) But It doesn't work Ignoring exception in command leaderboard: Tracebac

Solution 1:

Looking at the documentation for get_member, if the member is not found it returns None. Thus, since the error you are getting is that 'NoneType' has no attribute 'name,' that suggests that get_member returned None and based on the docs it only returns None if the member is not found.

I'd recommend adding


member = ctx.guild.get_member(id_) #your existing lineif member isNone:
    raise ValueError(f"Member with id {id_} not found")

Adding this if statement will automatically raise an error so that you can see when get_member returns None (ie doesn't find the result) so you can handle that appropriately.

Solution 2:

Sorry for all mistakes but thanks a lot!

thanks to @mr_mooo_cow and @user1558604

The code is

@client.command(aliases = ["lb"])asyncdefleaderboard(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 = 1for amt in total:
        id_ = leader_board[amt]
        member = await ctx.guild.fetch_member(id_) #your existing lineif member isNone:
            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:
            breakelse:
            index += 1await ctx.send(embed=em)

Post a Comment for "Economy Bot | Discord.py Rewrite | Leaderboard Error - Attributeerror: 'nonetype' Object Has No Attribute 'name'"