Toggle table of contents sidebar
CommandHandler¶Bases: telegram.ext.BaseHandler
Handler class to handle Telegram commands.
Commands are Telegram messages that start with a telegram.MessageEntity.BOT_COMMAND
(so with /
, optionally followed by an @
and the bot’s name and/or some additional text). The handler will add a list
to the CallbackContext
named CallbackContext.args
. It will contain a list of strings, which is the text following the command split on single or consecutive whitespace characters.
By default, the handler listens to messages as well as edited messages. To change this behavior use ~filters.UpdateType.EDITED_MESSAGE
in the filter argument.
Changed in version 20.0:
Renamed the attribute command
to commands
, which now is always a frozenset
Updating the commands this handler listens to is no longer possible.
command (str
| Collection[str
]) – The command or list of commands this handler should listen for. Case-insensitive. Limitations are the same as for telegram.BotCommand.command
.
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 from telegram.ext.filters.BaseFilter
. Standard filters can be found in telegram.ext.filters
. Filters can be combined using bitwise operators (&
for and
, |
for or
, ~
for not
)
Determines whether the return value of the callback should be awaited before processing the next handler in telegram.ext.Application.process_update()
. Defaults to True
.
has_args (bool
| int
, optional) –
Determines whether the command handler should process the update or not. If True
, the handler will process any non-zero number of args. If False
, the handler will only process if there are no args. if int
, the handler will only process if there are exactly that many args. Defaults to None
, which means the handler will process any or no args.
Added in version 20.5.
ValueError – When the command is too long or has illegal chars.
The set of commands this handler should listen for.
frozenset[str
]
The callback function for this handler.
Optional. Only allow updates with these filters.
Determines whether the return value of the callback should be awaited before processing the next handler in telegram.ext.Application.process_update()
.
Optional argument, otherwise all implementations of CommandHandler
will break. Defaults to None
, which means the handler will process any args or no args.
Added in version 20.5.
Determines whether an update should be passed to this handler’s callback
.
update (telegram.Update
| object
) – Incoming update.
The list of args for the handler.
Add text after the command to CallbackContext.args
as list, split on single whitespaces and add output of data filters to CallbackContext
as well.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4