Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Discord, check member status

I want to implement a function in my discord bot that check if any member has gone offline and then execute the following functions. I have read the API reference pages but couldn't quite understan how to do it, would something sort of like this work?

client = discord.Client()

@client.event
async def on_member_update(before, after):
    if before == online:
        if after == offline:
            print("{} has gone offline.".format(member))

I don't think the code will work as it is intended but it might provide some guidance to what I am aiming to do.

like image 561
PGillner Avatar asked Nov 25 '25 13:11

PGillner


1 Answers

Something like this?

@client.event
async def on_member_update(before, after):
    if str(before.status) == "online":
        if str(after.status) == "offline":
            print("{} has gone {}.".format(after.name,after.status))

That is if you want it to only trigger when the user has been online and goes "offline"
You can do something like

@client.event
async def on_member_update(before, after):
    if str(after.status) == "offline":
        print("{} has gone {}.".format(after.name,after.status))

if you want it to trigger when the user was "Idle" or "dnd" and went "offline".

like image 105
Tristo Avatar answered Nov 28 '25 01:11

Tristo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!