Reputation: 636
When a user sends a command message in discord, we always get the content of the user without the exact name of the command that they use for doing this command. For example:
@bot.command(aliases=['bonjour','hola','nihao'])
async def hello(ctx):
# do something
But, because there are aliases, users can use "hello", "bonjour", "hola", or "nihao" for calling this command. So, is there any way to get which one the user actually types for calling this command?
What I have tried (don't work):
ctx.command
will always give me "hello" even if I call this command with an alias.
ctx.command.aliases
will return me a list of aliases
So, this problem bothers me a lot. Any suggestion or help would be great!
Upvotes: 0
Views: 535
Reputation: 644
You can use ctx.invoked_with
"The command name that triggered this invocation. Useful for finding out which alias called the command.
Docs: discord.ext.commands.Context.invoked_with
Upvotes: 2
Reputation: 2720
You can check the alias used from the message content available as ctx.message.content
.
Something like the following should give you the exact alias
alias = ctx.message.content.lstrip('prefix').split()[0]
Note that you'll need to substitute your bot's actual prefix and that this will only work for commands that consist of a single word (though it can be adapted to work with longer commands as well)
Upvotes: 0