简体   繁体   中英

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.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM