Skip to main content
Command components are triggered by user command messages starting with ! (or other configured prefixes). Here’s an example of triggering the !help command:

Adding Command Components

A single plugin can contain any number of commands. Execute the command lbp comp Command in the plugin directory and follow the prompts to enter the command configuration.
This will generate info.yaml and info.py files in the components/commands/ directory. The .yaml file defines the basic information for the !info command, and the .py file is the command handler:

Manifest File: Command Component

Plugin Processing

The following code is generated by default (components/command/<command_name>.py). You need to register and implement subcommand processing logic in the initialize method of the Info class.
Adding subcommands:
In this code, the send function is registered as a subcommand through the @self.subcommand decorator, prints the command context (ExecuteContext) information, and concatenates it into a reply message.

Subcommand Registration

name is the subcommand name. Leaving it empty means handling the main command. If not empty, it matches the second parameter as the command. For example:
  • !info matches the subcommand with name=""
  • !info field matches the subcommand with name=“field”
  • !info field value matches the subcommand with name=“field”, with value as the subcommand parameter
  • Specialy, name="*" matches all unmatched first-level subcommands, and passes each section after info as parameters, for example !info 123, !info abc. You can get ['123'] or ['abc'] from context.crt_params, depending on the user’s input.
In subcommand functions, you can read command parameters through the context variable. The effect of the above command is shown in the image:

Command Context

Command Return Values

Command return values (CommandReturn) currently support returning text, images (image_url, image links), and errors.
Command processing supports returning multiple messages, so please use yield statements to return messages. For specific return values, please refer to the definition of CommandReturn: langbot_plugin.api.entities.builtin.command.context.CommandReturn

What’s Next

You have learned the basic information about command registration and command execution. Next, you can: