This filter can be helpful for handling commands from the text messages.

Works only with Message events which have the text.


Argument Type Description
commands Union[Sequence[Union[str, re.Pattern]], Union[str, re.Pattern]] List of commands (string or compiled regexp patterns)
commands_prefix str Prefix for command. Prefix is always is single char but here you can pass all of allowed prefixes, for example: "/!" will work with commands prefixed by "/" or "!" (Default: "/").
commands_ignore_case bool Ignore case (Does not work with regexp, use flags instead. Default: False)
commands_ignore_mention bool Ignore bot mention. By default bot can not handle commands intended for other bots (Default: False)


  1. Filter single variant of commands: Command(commands=["start"]) or Command(commands="start")
  2. Handle command by regexp pattern: Command(commands=[re.compile(r"item_(\d+)")])
  3. Match command by multiple variants: Command(commands=["item", re.compile(r"item_(\d+)")])
  4. Handle commands in public chats intended for other bots: Command(commands=["command"], commands)
  5. As keyword argument in registerer: @router.message(commands=["help"])


Command cannot include spaces or any whitespace

Allowed handlers

Allowed update types for this filter:

  • message
  • edited_message