Random Quote Sharing with Pyrogram

  • Share this:

Code introduction


This function, using the Pyrogram library, randomly selects a quote from a predefined list and sends it to a specified chat.


Technology Stack : Pyrogram

Code Type : Function

Code Difficulty : Intermediate


                
                    
from pyrogram import Client, filters
import random

def generate_random_quote():
    quotes = [
        "The only way to do great work is to love what you do. - Steve Jobs",
        "Success is not final, failure is not fatal: It is the courage to continue that counts. - Winston Churchill",
        "The best way to predict the future is to create it. - Peter Drucker",
        "Innovation distinguishes between a leader and a follower. - Steve Jobs",
        "The only limit to our realization of tomorrow will be our doubts of today. - Franklin D. Roosevelt"
    ]
    return random.choice(quotes)

def share_random_quote(client: Client, update: Update):
    quote = generate_random_quote()
    client.send_message(chat_id=update.chat.id, text=quote)

# Usage example:
# client = Client("your_api_id", "your_api_hash")
# client.add_handler(ChatHandler(filters.create(), share_random_quote))
# client.start()                
              
Tags: