telegram.ext.PrefixHandler#
- class telegram.ext.PrefixHandler(prefix, command, callback, filters=None, block=True)[source]#
Bases:
telegram.ext.CommandHandlerHandler class to handle custom prefix commands.
This is an intermediate handler between
MessageHandlerandCommandHandler. It supports configurable commands with the same options asCommandHandler. It will respond to every combination ofprefixandcommand. It will add alistto theCallbackContextnamedCallbackContext.args. It will contain a list of strings, which is the text following the command split on single or consecutive whitespace characters.Examples
Single prefix and command:
PrefixHandler("!", "test", callback) # will respond to '!test'.
Multiple prefixes, single command:
PrefixHandler(["!", "#"], "test", callback) # will respond to '!test' and '#test'.
Multiple prefixes and commands:
PrefixHandler( ["!", "#"], ["test", "help"], callback ) # will respond to '!test', '#test', '!help' and '#help'.
By default, the handler listens to messages as well as edited messages. To change this behavior use
~filters.UpdateType.EDITED_MESSAGENote
PrefixHandlerdoes not handle (edited) channel posts.
Warning
When setting
blocktoFalse, you cannot rely on adding custom attributes totelegram.ext.CallbackContext. See its docs for more info.- Parameters
prefix (
str| Tuple[str] | List[str]) – The prefix(es) that will precedecommand.command (
str| Tuple[str] | List[str]) – The command or list of commands this handler should listen for.callback (coroutine function) –
The callback function for this handler. Will be called when
check_update()has determined that an update should be processed by this handler. Callback signature:async def callback(update: Update, context: CallbackContext)
The return value of the callback is usually ignored except for the special case of
telegram.ext.ConversationHandler.filters (
telegram.ext.filters.BaseFilter, optional) – A filter inheriting fromtelegram.ext.filters.BaseFilter. Standard filters can be found intelegram.ext.filters. Filters can be combined using bitwise operators (&forand,|foror,~fornot)block (
bool, optional) – Determines whether the return value of the callback should be awaited before processing the next handler intelegram.ext.Application.process_update(). Defaults toTrue.
- block[source]#
Determines whether the return value of the callback should be awaited before processing the next handler in
telegram.ext.Application.process_update().- Type