telegram.ext.StringCommandHandler¶
- class telegram.ext.StringCommandHandler(command, callback, block=True)[source]¶
Bases:
telegram.ext.BaseHandler
BaseHandler class to handle string commands. Commands are string updates that start with
/
. The handler will add alist
to theCallbackContext
namedCallbackContext.args
. It will contain a list of strings, which is the text following the command split on single whitespace characters.Note
This handler is not used to handle Telegram
telegram.Update
, but strings manually put in the queue. For example to send messages with the bot using command line or API.Warning
When setting
block
toFalse
, you cannot rely on adding custom attributes totelegram.ext.CallbackContext
. See its docs for more info.- Parameters
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
.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
- check_update(update)[source]¶
Determines whether an update should be passed to this handler’s
callback
.
- collect_additional_context(context, update, application, check_result)[source]¶
Add text after the command to
CallbackContext.args
as list, split on single whitespaces.