Skip to main content

BotCommands

Derive Macro BotCommands 

Source
#[derive(BotCommands)]
{
    // Attributes available to this derive:
    #[command]
}
Expand description

Derive macro that generates command-parsing infrastructure for a Telegram bot.

Annotate an enum with #[derive(BotCommands)] to automatically generate:

  • parse(text, bot_name) -> Result<Self, ParseError> – parse incoming message text
  • descriptions() -> String – formatted help text for all commands
  • bot_commands() -> Vec<BotCommand> – suitable for the setMyCommands API call

§Enum-level attributes

AttributeDefaultDescription
rename_rule"identity"How variant names map to command strings
prefix"/"Command prefix character(s)
descriptionnoneGlobal description header for help text
command_separator" "Separator between the command and its arguments

§Variant-level attributes

AttributeDescription
descriptionHelp text for this command
renameOverride the command string for this variant
parse_with"default", "split", or a custom fn(String) -> Result<T, E>
separatorArgument separator when using parse_with = "split"
hideExclude from help text and bot_commands()