如何检查与我的机器人一起使用命令的用户的用户ID

问题描述 投票:0回答:1

[当某人在我的Discord机器人(discord.py)上使用命令时,我想检查其用户ID,如果它等于我的用户ID,它会打个招呼并说出我的等级。但这行不通,有什么想法吗?

这里是我当前的代码:

class rank(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command(aliases=["perms"])
    async def rank(self, ctx, member):
        if client.author.id == xxxx:
            await ctx.send(f"Your rank is Bot Owner..\nHello Chaseyy")
            return
        elif client.author.id == xx:
            await ctx.send("Your rank is Bot Admin\nHello Name")
            return
        else:
            await ctx.send("You are a Bot User")
        return
python command discord.py discord.py-rewrite
1个回答
1
投票

您可以执行以下操作来检索消息的用户标识:

ctx.author.id

ctx参数包含有关已发送消息的所有信息。使用:ctx.author我们检索用户。使用ctx.author.id检索该用户的ID。

© www.soinside.com 2019 - 2024. All rights reserved.