【发布时间】:2021-03-14 22:44:19
【问题描述】:
我尝试为我的经济型机器人添加排行榜功能。但我得到了这个错误:
Command raised an exception: AttributeError: module 'discord.ext.commands' has no attribute 'get_user'
我想我需要添加另一个库或类似的东西。
这是我的完整代码:
@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)
【问题讨论】:
标签: python discord discord.py