Skip to content

Custom Commands ​

There are two ways to add custom commands to Zero Ichi.

Method 1: Create a File ​

Create a Python file in the appropriate src/commands/<category>/ directory. The bot auto-discovers it on startup (or hot-reloads if auto_reload is enabled).

Basic Command ​

python
from core import symbols as sym
from core.command import Command, CommandContext
from core.i18n import t


class HelloCommand(Command):
    name = "hello"
    description = "Say hello"
    usage = "hello"

    async def execute(self, ctx: CommandContext) -> None:
        await ctx.client.reply(ctx.message, f"{sym.WAVE} Hello, {ctx.message.sender_name}!")

Command with Arguments ​

python
class SayCommand(Command):
    name = "say"
    description = "Repeat your message"
    usage = "say <text>"

    async def execute(self, ctx: CommandContext) -> None:
        if not ctx.raw_args:
            await ctx.client.reply(ctx.message, "Please provide text to say!")
            return
        await ctx.client.reply(ctx.message, ctx.raw_args)

Group-Only Admin Command ​

python
class AnnounceCommand(Command):
    name = "announce"
    description = "Make an announcement"
    usage = "announce <message>"
    group_only = True
    admin_only = True

    async def execute(self, ctx: CommandContext) -> None:
        if not ctx.raw_args:
            return
        await ctx.client.reply(ctx.message, f"📢 *Announcement*\n\n{ctx.raw_args}")

Method 2: Dynamic Command (Owner Only) ​

Create commands on the fly via WhatsApp with /addcommand:

/addcommand
from core.command import Command, CommandContext

class GreetCommand(Command):
    name = "greet"
    description = "Greet someone"
    usage = "greet"

    async def execute(self, ctx):
        await ctx.client.reply(ctx.message, "Greetings!")

Manage dynamic commands:

/listdynamic          # List all dynamic commands
/delcommand greet     # Delete a dynamic command

Command Properties ​

PropertyTypeDefaultDescription
namestr(required)Command name
aliaseslist[str][]Alternative names
descriptionstr""Help text
usagestr""Usage example
group_onlyboolFalseOnly in groups
private_onlyboolFalseOnly in DMs
admin_onlyboolFalseRequires admin
owner_onlyboolFalseRequires owner
bot_admin_requiredboolFalseBot must be admin
cooldownint0Cooldown in seconds

CommandContext ​

The ctx object passed to execute() provides:

PropertyTypeDescription
ctx.messageMessageHelperThe incoming message
ctx.clientBotClientThe bot client for sending messages
ctx.argslist[str]Parsed arguments
ctx.raw_argsstrRaw argument string
ctx.command_namestrCommand name used
ctx.prefixstrPrefix used to invoke

Adding i18n Support ​

To make your command translatable:

  1. Add keys to src/locales/en.json and src/locales/id.json
  2. Use t() in your command
python
from core.i18n import t

# In your execute method:
await ctx.client.reply(ctx.message, t("mycommand.greeting"))

See Internationalization for more details.

Built with ❤️