Skip to content

[FAQ] command: @bot

Housa Hitomi edited this page May 16, 2022 · 3 revisions

TL;DR

from khl.command import Rule

@bot.command(rules=[Rule.is_bot_mentioned(bot)])
async def echo(m: Message, n: int, mentioned: str):
    await m.reply(f'{mentioned}! you typed: {n}')

you can invoke this command such like /echo 2 @bot (do not forget the space between 2 and @bot)

why param mentioned is needed

look at the trigger message: /echo 2 @bot, this content can be viewed as a command with 2 args: 2 and @bot

you can customize your command scheme as well just follow general command design rules