Skip to main content
alterself processes only messages that you send yourself. It checks that 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.
Both decorators accept the same parameters:

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.
Given the prefix ".", the following inputs produce these results:
To capture everything after the command name as a single string, including spaces, annotate the last parameter with * or use a greedy string converter. This is useful for commands that take a sentence or a reason as input.
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 a Context 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 a CheckFailed you can handle with an error handler). alterself ships with three built-in checks:
You can also write a custom check. A check is any callable that accepts a 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.

Programmatic Registration

You can add, remove, and look up commands at runtime without using decorators:
Programmatic registration is useful for loading commands conditionally based on configuration flags, or for writing plugin systems that add and remove commands without touching your main file.