首页 > 解决方案 > python电报机器人发件人过滤器

问题描述

我想创建一个处理程序,当具体用户(@exampleuser)发布包含单词列表中单词的消息时触发。

这就是我所做的: dispatcher.add_handler(MessageHandler(Filters.regex(re.compile(r'*example word from the wordlist*', re.IGNORECASE)) and Filters.sender_chat(390077500)) , wordBan)

但它不起作用,但如果我只使用:dispatcher.add_handler(MessageHandler(Filters.sender_chat(*example user id*)) , wordBan)它起作用,但不是在具体用户发送消息时触发,而是在任何用户发送消息时触发。

如何添加具体的用户过滤器

标签: pythonpython-3.xtelegram-botpython-3.8python-telegram-bot

解决方案


利用

dispatcher.add_handler(MessageHandler(Filters.regex(re.compile(r'*example word from the wordlist*', re.IGNORECASE)) & Filters.sender_chat(390077500)) , wordBan)

您想使用&|组成 PTB 过滤器。


推荐阅读