Check if a specific user did a command discord.py

Im trying to make a command that I could use in every server, but when others use “-help” it doesn’t show in the list of commands. I know the normal way to do this would be:

if ctx.author.id == myID:
  #do some code

But if I do it like this, the user can still see that the command exists when using “-help”. Is there any way to get around this? Is there a @commands.command @commands.is_user(myID) ?

Answer

There are three options, you can either make a check, make a decorator, or make a global check:

1.

def is_user(ctx):
    return not ctx.author.id == myID

@bot.command()
@commands.check(is_user)
async def foo(ctx):
    ...
  1. decorator
def is_user(func):
    def wrapper(ctx):
        return not ctx.author.id == myID
    return commands.check(wrapper)

@bot.command()
@is_user
async def foo(ctx):
    ...
  1. global check
@bot.check
async def is_user(ctx):
    return not ctx.author.id == myID

If a check returns False, commands.CheckFailure is going to be raised, you can make an error handler and send something like “You can’t use this command” or whatever.

Reference: