You can download this code by clicking the button below.
This code is now available for download.
This function creates a Pyrogram bot that replies to messages containing specific text (such as 'hello').
Technology Stack : Pyrogram
Code Type : Pyrogram Bot Function
Code Difficulty : Intermediate
import pyrogram
from pyrogram import Client, filters
from pyrogram.handlers import MessageHandler
def create_bot_with_filter():
# Define the bot token and create a bot object
token = 'YOUR_BOT_TOKEN'
client = Client('my_bot', api_id=YOUR_API_ID, api_hash=YOUR_API_HASH)
# Define a filter for messages containing the word "hello"
hello_filter = filters.text('hello', case_sensitive=False)
# Create a handler for messages that match the filter
hello_handler = MessageHandler(lambda _, message: message.reply_text('Hello!'), filters=hello_filter)
# Add the handler to the client
client.add_handler(hello_handler)
# Start the client
client.start()
return client