H
H
hankipoiii2021-12-16 21:02:36
Python
hankipoiii, 2021-12-16 21:02:36

Trying to get user status (online/offline) by bot message(aiogram + pyrogram)?

I'm trying to do the following:
@dp.message_handler(regexp="View user")
async def checkuser(message: types.Message):
await message.answer("Enter username")
id = message.text
with app:
g = app. get_users("hankipoiii").status
print(g)
if g== "online":
timewentonline = datetime.datetime.now()
goodtime = datetime.datetime.today()
while g == "online":

timewentoff = datetime. datetime.now()
alltime = round((timewentoff - timewentonline).total_seconds())
if alltime >= 60:
await message.answer(
f"User with username {id} was online at {goodtime}\nTime spent online: {alltime / 60} minutes")
if alltime >= 3600:
await message.answer(
f"User with username {id} was online at {goodtime}\nTime spent online: {alltime / 3600} hours")
else:
await message.answer(
f"User with username {id} was online at {goodtime}\nTime spent online: {alltime} seconds")
writes the following:
AttributeError: 'coroutine' object has no attribute 'status'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
desaki, 2021-12-16
@desaki

g = await app.get_users("hankipoiii").status

S
soremix, 2021-12-16
@SoreMix

g = await app.get_users("hankipoiii")
print(g.status)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question