【问题标题】:Discord.py get_user(id)Discord.py get_user(id)
【发布时间】: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


    【解决方案1】:

    commands 不与成员打交道。

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

    例如

    member = ctx.guild.get_member(id_)
    

    member = self.bot.get_user(id_)
    

    【讨论】:

    • 考虑将正确的解决方案标记为正确的,你也会得到代表@Wardason
    猜你喜欢
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多