Random User Status Selector

  • Share this:

Code introduction


This function is used to randomly select and display a status from a user's status list. If the user's privacy settings restrict, a message is sent to explain. If there are no statuses, it informs the user that there are no statuses to display.


Technology Stack : Pyrogram

Code Type : Function function

Code Difficulty : Intermediate


                
                    
def random_user_status(update, context):
    from pyrogram import Client, filters
    from pyrogram.errors import UserPrivacyRestrictedError

    # Check if the user has restricted their privacy settings
    try:
        context.bot.get_user_status(update.effective_user)
    except UserPrivacyRestrictedError:
        return context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="This user has restricted their privacy settings."
        )

    # Send a random status from the user's status list
    status_list = context.bot.get_user_status(update.effective_user).status_list
    if not status_list:
        return context.bot.send_message(
            chat_id=update.effective_chat.id,
            text="This user has no status to show."
        )

    random_status = random.choice(status_list)
    context.bot.send_message(
        chat_id=update.effective_chat.id,
        text=random_status.content
    )                
              
Tags: