Pyrogram Function to Send Random Photo via Chat ID

  • Share this:

Code introduction


This code defines a function that sends a random photo to a specified chat ID. It uses the Pyrogram library's Client class and send_photo function, along with the Filters class to set sending options.


Technology Stack : Pyrogram

Code Type : Pyrogram Function

Code Difficulty : Intermediate


                
                    
def send_random_photo(chat_id, photo):
    from pyrogram import Client, Filters
    from pyrogram import functions as fn

    app = Client("my_bot", session_name="session", api_id=123456, api_hash="your_api_hash")

    with app:
        app.send_photo(chat_id, photo, filters=Filters.send_as_document)

app = Client("my_bot", session_name="session", api_id=123456, api_hash="your_api_hash")

with app:
    app.send_photo(123456789, "path_to_photo.jpg", filters=Filters.send_as_document)                
              
Tags: