Update Filters¶
Details¶
-
class
pyrogram.
Filters
¶ This class provides access to all library-defined Filters available in Pyrogram.
The Filters listed here are currently intended to be used with the
MessageHandler
only. At the moment, if you want to filter updates coming from different Handlers you have to create your own filters withcreate()
and use them in the same way.-
create
(name: str = None, **kwargs) → pyrogram.client.filters.filter.Filter¶ Easily create a custom filter.
Custom filters give you extra control over which updates are allowed or not to be processed by your handlers.
- Parameters
func (
callable
) – A function that accepts two positional arguments (filter, update) and returns a boolean: True if the update should be handled, False otherwise. The filter argument refers to the filter itself and can be used to access keyword arguments (read below). The update argument type will vary depending on which Handler is coming from. For example, in aMessageHandler
the update argument will be aMessage
; in aCallbackQueryHandler
the update will be aCallbackQuery
. Your function body can then access the incoming update attributes and decide whether to allow it or not.name (
str
, optional) – Your filter’s name. Can be anything you like. Defaults to “CustomFilter”.**kwargs (
any
, optional) – Any keyword argument you would like to pass. Useful when creating parameterized custom filters, such ascommand()
orregex()
.
-
me
= <pyrogram.client.filters.filters.MeFilter object>¶ Filter messages generated by you yourself.
-
bot
= <pyrogram.client.filters.filters.BotFilter object>¶ Filter messages coming from bots.
-
incoming
= <pyrogram.client.filters.filters.IncomingFilter object>¶ Filter incoming messages. Messages sent to your own chat (Saved Messages) are also recognised as incoming.
-
outgoing
= <pyrogram.client.filters.filters.OutgoingFilter object>¶ Filter outgoing messages. Messages sent to your own chat (Saved Messages) are not recognized as outgoing.
-
text
= <pyrogram.client.filters.filters.TextFilter object>¶ Filter text messages.
-
reply
= <pyrogram.client.filters.filters.ReplyFilter object>¶ Filter messages that are replies to other messages.
-
forwarded
= <pyrogram.client.filters.filters.ForwardedFilter object>¶ Filter messages that are forwarded.
-
caption
= <pyrogram.client.filters.filters.CaptionFilter object>¶ Filter media messages that contain captions.
-
edited
= <pyrogram.client.filters.filters.EditedFilter object>¶ Filter edited messages.
-
audio
= <pyrogram.client.filters.filters.AudioFilter object>¶ Filter messages that contain
Audio
objects.
-
document
= <pyrogram.client.filters.filters.DocumentFilter object>¶ Filter messages that contain
Document
objects.
-
photo
= <pyrogram.client.filters.filters.PhotoFilter object>¶ Filter messages that contain
Photo
objects.
-
sticker
= <pyrogram.client.filters.filters.StickerFilter object>¶ Filter messages that contain
Sticker
objects.
-
animation
= <pyrogram.client.filters.filters.AnimationFilter object>¶ Filter messages that contain
Animation
objects.
-
game
= <pyrogram.client.filters.filters.GameFilter object>¶ Filter messages that contain
Game
objects.
-
video
= <pyrogram.client.filters.filters.VideoFilter object>¶ Filter messages that contain
Video
objects.
-
media_group
= <pyrogram.client.filters.filters.MediaGroupFilter object>¶ Filter messages containing photos or videos being part of an album.
-
voice
= <pyrogram.client.filters.filters.VoiceFilter object>¶ Filter messages that contain
Voice
note objects.
-
video_note
= <pyrogram.client.filters.filters.VideoNoteFilter object>¶ Filter messages that contain
VideoNote
objects.
-
contact
= <pyrogram.client.filters.filters.ContactFilter object>¶ Filter messages that contain
Contact
objects.
-
location
= <pyrogram.client.filters.filters.LocationFilter object>¶ Filter messages that contain
Location
objects.
-
venue
= <pyrogram.client.filters.filters.VenueFilter object>¶ Filter messages that contain
Venue
objects.
-
web_page
= <pyrogram.client.filters.filters.WebPageFilter object>¶ Filter messages sent with a webpage preview.
-
poll
= <pyrogram.client.filters.filters.PollFilter object>¶ Filter messages that contain
Poll
objects.
-
private
= <pyrogram.client.filters.filters.PrivateFilter object>¶ Filter messages sent in private chats.
-
group
= <pyrogram.client.filters.filters.GroupFilter object>¶ Filter messages sent in group or supergroup chats.
-
channel
= <pyrogram.client.filters.filters.ChannelFilter object>¶ Filter messages sent in channels.
-
new_chat_members
= <pyrogram.client.filters.filters.NewChatMembersFilter object>¶ Filter service messages for new chat members.
-
left_chat_member
= <pyrogram.client.filters.filters.LeftChatMemberFilter object>¶ Filter service messages for members that left the chat.
-
new_chat_title
= <pyrogram.client.filters.filters.NewChatTitleFilter object>¶ Filter service messages for new chat titles.
-
new_chat_photo
= <pyrogram.client.filters.filters.NewChatPhotoFilter object>¶ Filter service messages for new chat photos.
-
delete_chat_photo
= <pyrogram.client.filters.filters.DeleteChatPhotoFilter object>¶ Filter service messages for deleted photos.
-
group_chat_created
= <pyrogram.client.filters.filters.GroupChatCreatedFilter object>¶ Filter service messages for group chat creations.
-
supergroup_chat_created
= <pyrogram.client.filters.filters.SupergroupChatCreatedFilter object>¶ Filter service messages for supergroup chat creations.
-
channel_chat_created
= <pyrogram.client.filters.filters.ChannelChatCreatedFilter object>¶ Filter service messages for channel chat creations.
-
migrate_to_chat_id
= <pyrogram.client.filters.filters.MigrateToChatIdFilter object>¶ Filter service messages that contain migrate_to_chat_id.
-
migrate_from_chat_id
= <pyrogram.client.filters.filters.MigrateFromChatIdFilter object>¶ Filter service messages that contain migrate_from_chat_id.
-
pinned_message
= <pyrogram.client.filters.filters.PinnedMessageFilter object>¶ Filter service messages for pinned messages.
-
game_high_score
= <pyrogram.client.filters.filters.GameHighScoreFilter object>¶ Filter service messages for game high scores.
-
reply_keyboard
= <pyrogram.client.filters.filters.ReplyKeyboardFilter object>¶ Filter messages containing reply keyboard markups
-
inline_keyboard
= <pyrogram.client.filters.filters.InlineKeyboardFilter object>¶ Filter messages containing inline keyboard markups
-
mentioned
= <pyrogram.client.filters.filters.MentionedFilter object>¶ Filter messages containing mentions
-
via_bot
= <pyrogram.client.filters.filters.ViaBotFilter object>¶ Filter messages sent via inline bots
-
service
= <pyrogram.client.filters.filters.ServiceFilter object>¶ Filter service messages.
A service message contains any of the following fields set: left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message, game_score.
-
media
= <pyrogram.client.filters.filters.MediaFilter object>¶ Filter media messages.
A media message contains any of the following fields set: audio, document, photo, sticker, video, animation, voice, video_note, contact, location, venue, poll.
-
scheduled
= <pyrogram.client.filters.filters.ScheduledFilter object>¶ Filter messages that have been scheduled (not yet sent).
-
from_scheduled
= <pyrogram.client.filters.filters.FromScheduledFilter object>¶ Filter new automatically sent messages that were previously scheduled.
-
static
command
(commands: str, prefixes: str = '/', case_sensitive: bool = False)¶ Filter commands, i.e.: text messages starting with “/” or any other custom prefix.
- Parameters
commands (
str
|list
) – The command or list of commands as string the filter should look for. Examples: “start”, [“start”, “help”, “settings”]. When a message text containing a command arrives, the command itself and its arguments will be stored in the command field of theMessage
.prefixes (
str
|list
, optional) – A prefix or a list of prefixes as string the filter should look for. Defaults to “/” (slash). Examples: “.”, “!”, [“/”, “!”, “.”], list(“.:!”). Pass None or “” (empty string) to allow commands with no prefix at all.case_sensitive (
bool
, optional) – Pass True if you want your command(s) to be case sensitive. Defaults to False. Examples: when True, command=”Start” would trigger /Start but not /start.
-
static
regex
(pattern, flags: int = 0)¶ Filter message texts or captions that match a given regular expression pattern.
- Parameters
pattern (
str
) – The RegEx pattern as string, it will be applied to the text or the caption of a message. When a pattern matches, all the Match Objects are stored in the matches field of theMessage
itself.flags (
int
, optional) – RegEx flags.
-
class
user
(users: int = None)¶ Filter messages coming from one or more users.
You can use set bound methods to manipulate the users container.
- Parameters
users (
int
|str
|list
) – Pass one or more user ids/usernames to filter users. For you yourself, “me” or “self” can be used as well. Defaults to None (no users).
-
class
chat
(chats: int = None)¶ Filter messages coming from one or more chats.
You can use set bound methods to manipulate the chats container.
- Parameters
chats (
int
|str
|list
) – Pass one or more chat ids/usernames to filter chats. For your personal cloud (Saved Messages) you can simply use “me” or “self”. Defaults to None (no chats).
-
static
callback_data
(data: str)¶ Filter callback queries for their data.
- Parameters
data (
str
|bytes
) – Pass the data you want to filter for.
-