Python Discord,检查成员(member)状态

标签 python discord discord.py

我想在我的 discord 机器人中实现一个功能,检查是否有任何成员离线,然后执行以下功能。我已经阅读了 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))

我认为代码不会按预期工作,但它可能会为我的目标提供一些指导。

最佳答案

这样的?

@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))

也就是说,如果您希望它仅在用户在线并“离线”时触发
你可以做类似的事情

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

如果您希望它在用户“空闲”或“dnd”并“离线”时触发。

关于Python Discord,检查成员(member)状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50838388/

相关文章:

python - 导入错误 : No module named PytQt5

python - Discord.py - 使用特定消息回复 DM

python - 命令不在 discord.py 2.0 中运行 - 没有错误,但在 discord.py 1.7.3 中运行

python - 不和谐.错误.禁止 : 403 FORBIDDEN (error code: 50013): Missing Permissions

来自具有键和值列表的列表的 Python 字典

python - Numpy 获取满足条件的坐标以及坐标?

python - 在 Discord 中仅从 1 个 channel 发送消息(discord.py bot)

python - 不和谐 py - message.mentions "else"没有任何结果

python - 如何在Tkinter界面中显示来自OpenCV的图像?

javascript - Discord.js 机器人数学无法正常工作