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:
Traceback (most recent call last):
File "C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "test.py", line 303, in leaderboard
name = member.name
AttributeError: 'NoneType' object has no attribute 'name'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'name'
Is there any way to fix this?
Code:
@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 = ctx.guild.get_member(id_)
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)