telegram.ext.filters module¶
This module contains the Filters for use with the MessageHandler class
-
class
telegram.ext.filters.BaseFilter¶ Bases:
objectBase class for all Message Filters
Subclassing from this class filters to be combined using bitwise operators:
And:
>>> (Filters.text & Filters.entity(MENTION))
Or:
>>> (Filters.audio | Filters.video)
Also works with more than two filters:
>>> (Filters.text & (Filters.entity(URL) | Filters.entity(TEXT_LINK)))
If you want to create your own filters create a class inheriting from this class and implement a filter method that returns a boolean: True if the message should be handled, False otherwise. Note that the filters work only as class instances, not actual class objects (so remember to initialize your filter classes).
-
filter(message)¶
-
-
class
telegram.ext.filters.Filters¶ Bases:
objectPredefined filters for use with the filter argument of
telegram.ext.MessageHandler.-
all= <telegram.ext.filters._All object>¶
-
audio= <telegram.ext.filters._Audio object>¶
-
command= <telegram.ext.filters._Command object>¶
-
contact= <telegram.ext.filters._Contact object>¶
-
document= <telegram.ext.filters._Document object>¶
-
class
entity(entity_type)¶ Bases:
telegram.ext.filters.BaseFilterFilters messages to only allow those which have a
telegram.MessageEntitywhere their type matches entity_type.Parameters: entity_type – Entity type to check for. All types can be found as constants in telegram.MessageEntity.Returns: function to use as filter
-
filter(message)¶
-
-
Filters.forwarded= <telegram.ext.filters._Forwarded object>¶
-
Filters.game= <telegram.ext.filters._Game object>¶
-
Filters.location= <telegram.ext.filters._Location object>¶
-
Filters.photo= <telegram.ext.filters._Photo object>¶
-
Filters.reply= <telegram.ext.filters._Reply object>¶
-
Filters.status_update= <telegram.ext.filters._StatusUpdate object>¶
-
Filters.sticker= <telegram.ext.filters._Sticker object>¶
-
Filters.text= <telegram.ext.filters._Text object>¶
-
Filters.venue= <telegram.ext.filters._Venue object>¶
-
Filters.video= <telegram.ext.filters._Video object>¶
-
Filters.voice= <telegram.ext.filters._Voice object>¶
-
-
class
telegram.ext.filters.MergedFilter(base_filter, and_filter=None, or_filter=None)¶ Bases:
telegram.ext.filters.BaseFilterRepresents a filter consisting of two other filters.
Parameters: - base_filter – Filter 1 of the merged filter
- and_filter – Optional filter to “and” with base_filter. Mutually exclusive with or_filter.
- or_filter – Optional filter to “or” with base_filter. Mutually exclusive with and_filter.
-
filter(message)¶