-
-
Notifications
You must be signed in to change notification settings - Fork 105
Using a Filter
You already learn how to create a command handler inside your custom plugins, now lets take a look how to use filter to it's handler.
~Anjani
have implementation of Filter it's slightly different than built-in Pyrogram Filter. But that doesn't mean you can't combine built-in Pyrogram Filter and Anjani Filter.
Let's take a look.
from pyrogram import filters
from pyrogram.types import Message
from anjani import command, listener, plugin
class ExampleFilter(plugin.Plugin):
@command.filters(filters.private)
async def cmd_test(self, ctx: command.Context) -> str:
return "We passed the Filter!"
@listener.filters(filters.private & filters.reply)
async def on_message(self, message: Message) -> None:
self.log.info("Received a reply message: %s", message.reply_to_message.text)
So what happens there? First we register the command /test
with filters.private
means the command only runs on private message (PM).
Then we register on_message
listener with filters.private
and filters.reply
.
Then if we called the command the bot will reply "We passed the Filter!" then log into terminal "Received a reply message: /test".
For more information about using a Filter refers to Pyrogram Filter documentation HERE
Wiki of Anjani © Copyright 2021, UserBotIndo