ContentTypesFilter#

class aiogram.filters.content_types.ContentTypesFilter(*, content_types: Union[Sequence[str], str])[source]#

Is useful for handling specific types of messages (For example separate text and stickers handlers).

content_types: Union[Sequence[str], str]#

Sequence of allowed content types

Can be imported:

  • from aiogram.filters.content_types import ContentTypesFilter

  • from aiogram.filters import ContentTypesFilter

Or used from filters factory by passing corresponding arguments to handler registration line

Usage#

  1. Single content type: ContentTypesFilter(content_types=["sticker"]) or ContentTypesFilter(content_types="sticker")

  2. Multiple content types: ContentTypesFilter(content_types=["sticker", "photo"])

  3. Recommended: With usage of ContentType helper: ContentTypesFilter(content_types=[ContentType.PHOTO])

  4. Any content type: ContentTypesFilter(content_types=[ContentType.ANY])

Allowed handlers#

Allowed update types for this filter:

  • message

  • edited_message

  • channel_post

  • edited_channel_post