问题描述
im试图创建一个Python脚本来检查用户是否在线。 我使用telethon成功地在Telegram和python之间度过了一个赛季,但是Im确实很难获得正确的语法来获取我的联系状态之一。 任何帮助都会被申请!
from telethon.tl.types import UserStatusOnline,UserStatusOffline,ContactStatus
from telethon.sync import TelegramClient
from datetime import datetime
### Client Side ###
phone = "+"
api_id =
api_hash = ""
client = TelegramClient(phone,api_id,api_hash)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone,input('Enter the code: '))
else:
print("Logging Complete")
account = client.get_entity('chats_name')
if isinstance(account.status,UserStatusOffline):
if contact.online != False:
contact.online = False
event.respond(f'{utc2localtime(account.status.was_online).strftime(DATETIME_FORMAT)}: {contact.name} went offline.')
elif contact.last_offline != account.status.was_online:
if contact.last_offline is not None:
event.respond(f'{utc2localtime(account.status.was_online).strftime(DATETIME_FORMAT)}: {contact.name} went offline after being online for short time.')
else:
event.respond(f'{utc2localtime(account.status.was_online).strftime(DATETIME_FORMAT)}: {contact.name} went offline.')
contact.last_offline = account.status.was_online
elif isinstance(account.status,UserStatusOnline):
if contact.online != True:
contact.online = True
event.respond(f'{datetime.now().strftime(DATETIME_FORMAT)}: {contact.name} went online.')
else:
if contact.online != False:
contact.online = False
event.respond(f'{datetime.now().strftime(DATETIME_FORMAT)}: {contact.name} went offline.')
contact.last_offline = None
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)