Skip to content

📃 Help page

Providing clear help information is essential for users. PBModular offers two ways for modules to define their help content, which is typically displayed by a core command like /mhelp YourModuleName.

1. Automatic Generation (Default)

If you don't explicitly define a help page, the framework attempts to generate one automatically when /help YourModuleName is invoked.

  • It lists all commands registered by the module using the @command decorator.
  • For each command, it uses the docstring.
  • The output format is typically /command_name - Description from docstring.

To use automatic help effectively:

  • Ensure all your @command-decorated methods have clear and concise docstrings explaining their purpose and usage.

2. Manual Help Page (help_page Property)

For more control over the help content, including custom formatting, explanations beyond command lists, or adding inline buttons, you can override the help_page property in your main BaseModule class.

This property should return either:

  • A base.module.HelpPage object: This dataclass allows specifying both text and optional inline keyboard buttons.
  • A simple str: For backward compatibility, you can just return a string, which will be used as the message text. Using HelpPage is preferred for new development.

Using HelpPage Dataclass:

python
# main.py (inside your BaseModule class)
from base.module import HelpPage # Import the dataclass
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup

# ... other imports ...

    @property
    def help_page(self) -> HelpPage:
        """Provides a custom help page for this module."""
        text = (
            f"**{self.module_info.name} v{self.module_info.version} Help**\n\n"
            f"{self.module_info.description}\n\n"
            "**Available Commands:**\n"
            f"`/command1` - {self.S['help']['command1_desc']}\n" # Use translations!
            f"`/command2 [option]` - {self.S['help']['command2_desc']}\n\n"
            "Use the buttons below for more options."
        )
        buttons = [
            [ # Row 1
                InlineKeyboardButton("Detailed Guide", url=self.module_info.src_url or "https://example.com/docs"),
                InlineKeyboardButton("Settings Callback", callback_data=f"{self.module_info.name}:settings")
            ],
            [ # Row 2
                InlineKeyboardButton("Close Help", callback_data="close_help")
            ]
        ]
        return HelpPage(text=text, buttons=buttons)