You can download this code by clicking the button below.
This code is now available for download.
This function creates a Pyrogram bot that randomly replies with a quote when it receives a non-edited text message.
Technology Stack : Pyrogram
Code Type : Pyrogram Custom Function
Code Difficulty : Intermediate
from pyrogram import Client, filters
from pyrogram.types import Message
import random
def create_random_quote(arg1, arg2):
app = Client("userbot", session_name="random_quote_bot", api_id=arg1, api_hash=arg2)
@app.on_message(filters.text & ~filters.edited)
async def random_quote_handler(client: Client, message: Message):
quotes = [
"The only way to do great work is to love what you do.",
"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.",
"The future belongs to those who believe in the beauty of their dreams."
]
quote = random.choice(quotes)
await message.reply_text(quote)
app.run()