ChatMemberUpdated¶
Usage¶
Handle user leave or join events
from aiogram.filters import IS_MEMBER, IS_NOT_MEMBER
@router.chat_member(ChatMemberUpdatedFilter(IS_MEMBER >> IS_NOT_MEMBER))
async def on_user_leave(event: ChatMemberUpdated): ...
@router.chat_member(ChatMemberUpdatedFilter(IS_NOT_MEMBER >> IS_MEMBER))
async def on_user_join(event: ChatMemberUpdated): ...
Or construct your own terms via using pre-defined set of statuses and transitions.
Explanation¶
- class aiogram.filters.chat_member_updated.ChatMemberUpdatedFilter(member_status_changed: _MemberStatusMarker | _MemberStatusGroupMarker | _MemberStatusTransition)[source]¶
- member_status_changed¶
You can import from aiogram.filters
all available
variants of statuses, status groups or transitions:
Statuses¶
name |
Description |
---|---|
|
Chat owner |
|
Chat administrator |
|
Member of the chat |
|
Restricted user (can be not member) |
|
Isn’t member of the chat |
|
Kicked member by administrators |
Statuses can be extended with is_member flag by prefixing with
+
(for is_member == True)
or -
(for is_member == False
) symbol,
like +RESTRICTED
or -RESTRICTED
Status groups¶
The particular statuses can be combined via bitwise or
operator, like CREATOR | ADMINISTRATOR
name |
Description |
---|---|
|
Combination of |
|
Combination of |
|
Combination of |
Transitions¶
Transitions can be defined via bitwise shift operators >>
and <<
.
Old chat member status should be defined in the left side for >>
operator (right side for <<
)
and new status should be specified on the right side for >>
operator (left side for <<
)
The direction of transition can be changed via bitwise inversion operator: ~JOIN_TRANSITION
will produce swap of old and new statuses.
name |
Description |
---|---|
|
Means status changed from |
|
Means status changed from |
|
Means status changed from
|
Note
Note that if you define the status unions (via |
) you will need to add brackets for the statement
before use shift operator in due to operator priorities.
Allowed handlers¶
Allowed update types for this filter:
my_chat_member
chat_member