繁体   English   中英

Discord.py get_user(id)

[英]Discord.py get_user(id)

我尝试为我的经济机器人添加排行榜功能。 但是我得到了这个错误: 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)

commands不处理成员。

使用上下文或机器人用户来获取用户。

例如

member = ctx.guild.get_member(id_)

或者

member = self.bot.get_user(id_)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM