Filter Online Users Using Telethon

  • Share this:

Code introduction


This function accepts a client object and a list of users, then filters out users who are online.


Technology Stack : Telethon

Code Type : Telethon API Function

Code Difficulty : Intermediate


                
                    
def filter_online_users(client, users):
    """
    This function filters out users that are online from a list of users using Telethon.
    """
    online_users = []
    for user in users:
        try:
            if client.get_entity(user).status == 'online':
                online_users.append(user)
        except Exception as e:
            print(f"Error checking status for {user}: {e}")
    return online_users

# JSON Explanation                
              
Tags: