Discord.py get_user(id) [英] Discord.py get_user(id)

查看:24
本文介绍了Discord.py get_user(id)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向我的经济机器人添加排行榜功能.但是我得到了这个错误:命令引发异常:AttributeError:模块'discord.ext.commands'没有属性'get_user'我想我需要添加另一个库或类似的东西.这是我完整的代码:

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)

推荐答案

命令不处理成员.

使用上下文或漫游器用户来获取用户.

Use context or the bot user to get the user.

例如

member = ctx.guild.get_member(id_)

member = self.bot.get_user(id_)

这篇关于Discord.py get_user(id)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆