Hasti
Hasti

Reputation: 1

get status user in telegram every 1 minute

I want to check a user's online status every 1 minute. I used the following code but after a while I received the following error.

from telethon import TelegramClient, events, sync
import time

api_id = my_api_id
api_hash = my_api_hash
username = my_username

client = TelegramClient(username, api_id, api_hash)
client.start()
while True:
    account = client.get_entity(target_username)
    print(account.status.to_dict())
    time.sleep(60)

Error after working for a while:

A wait of 56063 seconds is required (caused by ResolveUsernameRequest)
  1. How can i get status user in telegram for every 1 minute?(unlimited)
  2. Is there a socket that sends the status of users?

Upvotes: 0

Views: 1181

Answers (1)

Lonami
Lonami

Reputation: 7141

The closest you can get is events.UserUpdate, for things like "user is typing" and so on.

@client.on(events.UserUpdate)
async def handler(event):
    ...  # use event

You can also use the user ID instead of the username which has lower flood limits. However, Telegram can still suspect of API misuse and issue any flood limits it wants.

Upvotes: 1

Related Questions