简体   繁体   English

Python Discord,检查成员状态

[英]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. 我想在我的discord机器人中实现一个功能,该功能检查是否有成员脱机,然后执行以下功能。 I have read the API reference pages but couldn't quite understan how to do it, would something sort of like this work? 我已经阅读了API参考页面,但不太了解如何执行此操作,这种方法会起作用吗?

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". 如果您希望它在用户“空闲”或“ dnd”并进入“离线”时触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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