Retrieving User Status via Pyrogram

  • Share this:

Code introduction


This code defines a function that can retrieve and reply to the status information of a specified user ID. If the user has set a status, the function will reply with that status; if not, it will reply that the user has not set a status.


Technology Stack : Pyrogram

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_user_status(client, user_id):
    from pyrogram import Client, filters
    from pyrogram.types import UserStatus

    @client.on_message(filters.private & filters.incoming)
    async def handle_status(client, message):
        if message.from_user.id == user_id:
            status = message.from_user.status
            if status:
                await message.reply(f"Current status of user {user_id}: {status}")
            else:
                await message.reply("User has no status set.")

    return "random_user_status"                
              
Tags: