{"record":{"id":"498f8421c41a159f","repo":"python-telegram-bot/python-telegram-bot","slug":"you-can-not-filter-for-users-and-include-anonymous","errorCode":null,"errorMessage":"You can not filter for users and include anonymous reactions. Set `message_reaction_types` to MESSAGE_REACTION_UPDATED.","messagePattern":"You can not filter for users and include anonymous reactions\\. Set `message_reaction_types` to MESSAGE_REACTION_UPDATED\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/telegram/ext/_handlers/messagereactionhandler.py","lineNumber":131,"sourceCode":"        self: \"MessageReactionHandler[CCT, RT]\",\n        callback: HandlerCallback[Update, CCT, RT],\n        chat_id: SCT[int] | None = None,\n        chat_username: SCT[str] | None = None,\n        user_id: SCT[int] | None = None,\n        user_username: SCT[str] | None = None,\n        message_reaction_types: int = MESSAGE_REACTION,\n        block: DVType[bool] = DEFAULT_TRUE,\n    ):\n        super().__init__(callback, block=block)\n        self.message_reaction_types: int = message_reaction_types\n\n        self._chat_ids = parse_chat_id(chat_id)\n        self._chat_usernames = parse_username(chat_username)\n        if (user_id or user_username) and message_reaction_types in (\n            self.MESSAGE_REACTION,\n            self.MESSAGE_REACTION_COUNT_UPDATED,\n        ):\n            raise ValueError(\n                \"You can not filter for users and include anonymous reactions. Set \"\n                \"`message_reaction_types` to MESSAGE_REACTION_UPDATED.\"\n            )\n        self._user_ids = parse_chat_id(user_id)\n        self._user_usernames = parse_username(user_username)\n\n    def check_update(self, update: object) -> bool:\n        \"\"\"Determines whether an update should be passed to this handler's :attr:`callback`.\n\n        Args:\n            update (:class:`telegram.Update` | :obj:`object`): Incoming update.\n\n        Returns:\n            :obj:`bool`\n\n        \"\"\"\n        if not isinstance(update, Update):\n            return False","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/python-telegram-bot/python-telegram-bot/blob/d3b69d2e9fb7af6c796f84516cfda751752c7cb7/src/telegram/ext/_handlers/messagereactionhandler.py#L113-L149","documentation":"MessageReactionHandler can filter by users, but anonymous reactions ( MESSAGE_REACTION and MESSAGE_REACTION_COUNT_UPDATED reaction types) have no user attached. Filtering by user_id/user_username while including those anonymous reaction types is contradictory, so __init__ raises ValueError immediately.","triggerScenarios":"MessageReactionHandler(user_id=..., user_username=..., message_reaction_types=MessageReactionHandler.MESSAGE_REACTION) — or MESSAGE_REACTION_COUNT_UPDATED — or an iterable containing them. Any user filter combined with anonymous reaction types raises at construction time.","commonSituations":"Wanting to track all reactions including anonymous ones while also restricting to a specific user. Developers often pass message_reaction_types=MessageReactionHandler.ALL_TYPES together with user_id, which includes the anonymous types.","solutions":["Set message_reaction_types to MessageReactionHandler.MESSAGE_REACTION_UPDATED (the non-anonymous type) when filtering by user","Or drop the user_id/user_username arguments to keep anonymous reactions","If you need both, register two handlers: one user-filtered for MESSAGE_REACTION_UPDATED and one unfiltered for anonymous types"],"exampleFix":"# before\nMessageReactionHandler(\n    callback,\n    user_id=12345,\n    message_reaction_types=MessageReactionHandler.ALL_TYPES,\n)\n\n# after\nMessageReactionHandler(\n    callback,\n    user_id=12345,\n    message_reaction_types=MessageReactionHandler.MESSAGE_REACTION_UPDATED,\n)","handlingStrategy":"validation","validationCode":"from telegram.ext import MessageReactionHandler\nanonymous = (MessageReactionHandler.MESSAGE_REACTION, MessageReactionHandler.MESSAGE_REACTION_COUNT_UPDATED)\ndef is_valid(user_id, user_username, types):\n    has_user = bool(user_id or user_username)\n    included = types in anonymous or (isinstance(types, (list, tuple, set)) and any(t in anonymous for t in types))\n    return not (has_user and included)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember anonymous reactions have no user by definition","Construct handlers in a helper that enforces the user/anonymous-type exclusion"],"tags":["python","telegram-bot","messagereactionhandler","filter-validation","anonymous-reactions"],"backgroundTag":"invalid-filter-combination","analyzedSha":"d3b69d2e9fb7af6c796f84516cfda751752c7cb7","analyzedAt":"2026-08-28T16:18:54.805Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}