CommandObject
in package
Readonly DTO carrying the parsed pieces of a Telegram slash-command (`/cmd@mention args`). Produced by {@see Command}::__invoke and injected into the handler kwargs under the `command` key.
Mirrors upstream aiogram.filters.command.CommandObject
(aiogram/filters/command.py:202-237). Field order matches the upstream
@dataclass declaration: prefix, command, mention, args,
regexp_match, magic_result.
Field role summary:
prefix: leading character(s) before the command name (/,!, …). ACommandfilter can register multiple prefixes; the matched one ends up here.command: command name without prefix or@mention.mention: optional@-suffixed bot mention, normalised (the leading@is stripped) —nullwhen the input had no@suffix. Upstream issue aiogram/aiogram#1013 makes the absence explicit; we mirror that in the parser by storingnull(not'') when no mention was present.args: post-command remainder verbatim;nullif the user wrote no args at all. Upstream'stext.split(maxsplit=1)is mirrored bypreg_split('/\s+/', $rest, 2)inCommand::parseCommand, which consumes the first run of whitespace and preserves the tail.regexpMatch: the regex match payload if the command was matched via a regex pattern. Surface only — populated in Phase 4.5+ when theCommand(string|Regex|BotCommand ...)variants land.magicResult: result of aMagicFilter-based post-validation. Also Phase 4.5+; surface today so a follow-up patch can drop the field in without churning the DTO shape.
Both regexpMatch/magicResult mirror upstream's repr=False semantic
by simply staying out of any __toString-style helper — there's no
stable PHP convention for excluding fields from var_dump, but no
production code path inspects them anyway.
Table of Contents
Properties
- $args : string|null
- $command : string
- $magicResult : mixed
- $mention : string|null
- $prefix : string
- $regexpMatch : array<string|int, mixed>|null
Methods
- __construct() : mixed
- mentioned() : bool
- Whether the command carried an `@bot_username` mention. Mirrors upstream's derived `mentioned` property at `aiogram/filters/command.py:220-225`.
- mentionWithoutPrefix() : string|null
- Mention with any leading `@` stripped, or `null` when no mention is stored. Matches upstream's `mention_without_prefix` convenience used by `Command.validate_mention` when comparing against `bot.me().username`.
- text() : string
- Reassemble the original textual command from the parsed parts. Mirrors upstream's `text` property (`aiogram/filters/command.py:228-237`) and provides a round-trip for logging / display purposes.
Properties
$args
public
string|null
$args
= null
$command
public
string
$command
= ''
$magicResult
public
mixed
$magicResult
= null
$mention
public
string|null
$mention
= null
$prefix
public
string
$prefix
= '/'
$regexpMatch
public
array<string|int, mixed>|null
$regexpMatch
= null
Methods
__construct()
public
__construct([string $prefix = '/' ][, string $command = '' ][, string|null $mention = null ][, string|null $args = null ][, array<int|string, mixed>|null $regexpMatch = null ][, mixed $magicResult = null ]) : mixed
Parameters
- $prefix : string = '/'
- $command : string = ''
- $mention : string|null = null
- $args : string|null = null
- $regexpMatch : array<int|string, mixed>|null = null
-
Capture groups from a regex match, when the matching command pattern was a regex (Phase 4.5+). Null otherwise.
- $magicResult : mixed = null
-
Result of a magic-filter post-validation (Phase 4.5+). Null otherwise.
mentioned()
Whether the command carried an `@bot_username` mention. Mirrors upstream's derived `mentioned` property at `aiogram/filters/command.py:220-225`.
public
mentioned() : bool
Implementation note: Python uses bool(self.mention) which collapses
empty strings to false. We mirror by combining the null check with an
explicit emptiness guard so mention: '' (defensive callers) does not
suddenly count as mentioned.
Return values
boolmentionWithoutPrefix()
Mention with any leading `@` stripped, or `null` when no mention is stored. Matches upstream's `mention_without_prefix` convenience used by `Command.validate_mention` when comparing against `bot.me().username`.
public
mentionWithoutPrefix() : string|null
The current parser already strips the @ before storing, but this
helper is the canonical accessor so user-land code can recover the
unprefixed form from a CommandObject built by hand (tests, fixtures).
Return values
string|nulltext()
Reassemble the original textual command from the parsed parts. Mirrors upstream's `text` property (`aiogram/filters/command.py:228-237`) and provides a round-trip for logging / display purposes.
public
text() : string