Reputation: 105
I try to add a leaderboard feature to my economy bot. But I got this Error:
Command raised an exception: AttributeError: module 'discord.ext.commands' has no attribute 'get_user'
I think I need to add another library or something like that.
Here is my complete code:
@commands.command()
async def leaderboard(self, ctx, x=1):
users = await self.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",
description="This is decided on the basis of raw money in the bank and wallet",
color=random.randint(0, 0xffffff))
index = 1
for amt in total:
id_ = leader_board[amt]
member = commands.get_user(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)
Upvotes: 0
Views: 315
Reputation: 2907
commands
doesn't deal with members.
Use context or the bot user to get the user.
For example
member = ctx.guild.get_member(id_)
or
member = self.bot.get_user(id_)
Upvotes: 1