Skip to content

[FEATURE] Add chat_id in ChatMemberHandler to Filter Specific Chat(s) #4287

@uniquetrij

Description

@uniquetrij

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

ChatMemberHandler can include a chat_id param to filter only on specified chat(s).

Describe the solution you'd like

It would be convenient to be able to do something like this:

application.add_handler(
    ChatMemberHandler(member_callback_1, ChatMemberHandler.CHAT_MEMBER, chat_id=<chat_id_1>)
)

application.add_handler(
    ChatMemberHandler(member_callback_2, ChatMemberHandler.CHAT_MEMBER, chat_id=<chat_id_2>)
)

Describe alternatives you've considered

async def member_callback_1(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    if update.chat_member.chat.id != <chat_id_1>:
        return
    ...

async def member_callback_2(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    if update.chat_member.chat.id != <chat_id_2>:
        return
    ...

Additional context

Let me know if there is an alternate / better way to achieve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions