message.author.id == client.me.id before attempting to match any prefix or command. This means your commands are entirely private; other users cannot trigger them. The command system handles prefix matching, argument tokenisation, check evaluation, and invocation for you so you can focus on writing the handler logic.
Defining Commands
You can register a command in two ways: with the@bot.command() decorator bound to your client instance, or with the standalone @alterself.cmd() decorator that works inside Cogs.
Arguments
alterself splits the text after the command name on whitespace and passes each token as a positional argument to your handler function. Default parameter values are used when the caller omits an argument.".", the following inputs produce these results:
Arguments are always received as strings. Convert them to
int, float, or other types inside your handler, and handle ValueError gracefully if the input might be invalid.The Context Object
Every command handler receives aContext object as its first argument (named ctx by convention). It bundles together everything you need to understand and respond to the invocation.
A typical handler uses several of these together:
Checks
Checks are predicate functions that run before your handler. If any check fails, the command is silently skipped (or raises aCheckFailed you can handle with an error handler). alterself ships with three built-in checks:
Context and returns a bool:
Checks are evaluated in the order they are stacked. Stack multiple
@alterself.check() decorators to require all conditions to pass simultaneously.