-
Notifications
You must be signed in to change notification settings - Fork 43
[FAQ] command prefix
- change prefix from '/'(this is default prefix) -> '.' & '。'
@bot.command(prefixes=['.', '。'])
async def foo(msg: Message):
...
- change prefix globally:
bot.command.update_prefixes('.', '。')
insert this snippet after all command were registered(typically before bot.run()
)
besides, update_prefixes()
can be called in command
prefixes in khl.py command are specific to those Commands with DefaultLexer
what's lexer?
lexer is a component to tear down Message content into tokens, for convenience in making powerful command matching and parsing
lexer is designed according to lexical analysis(wikipedia)
now, there are two kinds of lexer provided by official khl.py:
- DefaultLexer
- implemented via python package shlex, acts like shell
- RELexer
- implemented via regex, acts as what user defines
due to current design.
since using a prefix to invoke a command is ubiquitous in games/bots/shells, khl.py introduces prefix into Command to invoke command as well
but commands using other lexer(such as RELexer) control invoking themselves (e.g. RELexer uses regexp defined by user to invoke)
so prefixes only available in DefaultLexer