pytdbot.filters

class pytdbot.filters.Filter(func)[source]

Bases: object

Filter class

A filter is a function that takes a request and returns a boolean. If the returned value is True then the handler will be called. See create() for more information

Parameters:

func (Callable)

__init__(func)[source]
Parameters:

func (Callable)

pytdbot.filters.create(func)[source]

A factory to create a filter

Example

from pytdbot import filters, Client

client = Client(...)

# Create a filter by a decorator
@filters.create
async def filter_photo(_, event) -> bool:
    if event.content_type == "messagePhoto":
        return True
    return False

# Or by a function

filter_photo = filters.create(filter_photo)

# Or by lambda

filter_photo = filters.create(lambda _, event: event.content_type == "messagePhoto")

@client.on_updateNewMessage(filters=filter_photo)
async def photo_handler(c,update):
    await update.reply_text('I got a photo!')

client.run()
Parameters:

func (Callable) – The filter function

Return type:

Filter