Filters¶
Filters decide which updates reach a handler. They are passed to a decorator or to a handler
class, and they compose with & (and), | (or) and ~ (not):
from pyrogram import filters
@app.on_message(filters.text & filters.private & ~filters.bot)
async def only_humans_in_dm(client, message):
...
See Using Filters for how they combine, and Creating Filters for writing your own.
Callable filters¶
These take arguments and return a filter:
Filter |
Matches |
|---|---|
|
messages starting with a command |
|
messages whose text or caption matches a regex |
|
updates from specific users, by id or username |
|
updates from specific chats, by id or username |
|
messages in specific forum topics |
|
a custom filter from your own predicate |
filters.user, filters.chat and filters.topic build mutable sets — you can add and
remove entries on a live client, which is what makes an allow-list handler possible without
re-registering it.
Origin and direction¶
Filter |
Matches |
|---|---|
|
everything |
|
messages sent by yourself |
|
messages sent by a bot |
|
messages sent on behalf of a chat |
|
messages received |
|
messages sent |
|
forwarded messages |
|
messages sent via an inline bot |
|
messages that mention you |
|
messages that reply to another |
|
replies that quote part of the original |
|
scheduled messages |
|
messages that were scheduled and have now been sent |
|
channel posts automatically forwarded to a discussion group |
|
messages arriving through a business connection |
|
messages that cost Stars to send |
Chat kind¶
Filter |
Matches |
|---|---|
|
private chats |
|
private chats (alias of |
|
groups and supergroups |
|
channels |
|
chats with topics enabled |
|
chats where you are an administrator |
Content¶
Filter |
Matches |
|---|---|
|
text messages |
|
messages with a caption |
|
any media message |
|
messages that are part of an album |
|
media hidden behind a spoiler |
|
media with a self-destruct timer |
|
photos |
|
videos |
|
video notes |
|
animations (GIFs) |
|
audio files |
|
voice notes |
|
documents |
|
stickers |
|
stories |
|
messages with a link preview |
|
shared contacts |
|
locations |
|
live locations |
|
venues |
|
polls |
|
dice |
|
games |
Keyboards and interaction¶
Filter |
Matches |
|---|---|
|
messages carrying a reply keyboard |
|
messages carrying an inline keyboard |
|
users shared through a request button |
|
a chat shared through a request button |
Gifts, giveaways and payments¶
Filter |
Matches |
|---|---|
|
gift service messages |
|
premium gift codes |
|
a pending purchase offer for a unique gift |
|
an accepted purchase offer |
|
a declined purchase offer |
|
giveaway messages |
|
giveaway winner announcements |
|
successful payment service messages |
|
game high score service messages |
Service messages¶
Filter |
Matches |
|---|---|
|
any service message |
|
members joining |
|
a member leaving |
|
the chat title changing |
|
the chat photo changing |
|
the chat photo being removed |
|
a message being pinned |
|
a group being created |
|
a supergroup being created |
|
a channel being created |
|
a group migrating to a supergroup |
|
the supergroup a group migrated from |
|
a video chat starting |
|
a video chat ending |
|
members invited to a video chat |
Base classes¶
- filters.create()¶
- filters.command()¶
- filters.regex()¶