Retrieving User Status with Privacy Check

  • Share this:

Code introduction


This function is used to get the current status of a specified user. If the user's privacy settings restrict status viewing, it returns a prompt message.


Technology Stack : Pyrogram

Code Type : Pyrogram API Function

Code Difficulty : Intermediate


                
                    
def random_user_status(user_id, bot):
    from pyrogram import Client, filters
    from pyrogram.errors import UserPrivacyRestricted

    try:
        user = bot.get_users(user_id)
        status = user.status
        return status
    except UserPrivacyRestricted:
        return "This user has restricted their status privacy."                
              
Tags: