Chaseyy
Chaseyy

Reputation: 21

How can I check the user ID of someone who uses a command with my bot

When someone uses a command with my discord bot (discord.py), I want to check their user ID, if it is equal to mine, then it says hello back and says my rank. But it wont work, any ideas?

Heres my current code:

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

Upvotes: 0

Views: 412

Answers (1)

Deru
Deru

Reputation: 1172

You can do the following to retrieve the user id of an message:

ctx.author.id

The ctx param contains all the information about the message sent. Using: ctx.author we retrieve the user. Using ctx.author.id we retrieve the id of that user.

Upvotes: 1

Related Questions