繁体   English   中英

Discord.py 查看会员状态

[英]Discord.py check member status

我正在尝试为我的 discord 机器人编写一段代码,当我朋友的个人资料状态从离线更新为在线时,它会发出通知。

目前,我正在摆弄一些代码,这是我目前所拥有的:

@client.event
async def on_member_update(before, after)
    if str(before.status) == "offline":
        if str(after.status) == "online":
            await message.channel.send(f"""{} is now {}""".format(after.name,after.status))

这似乎不起作用。

您必须比较两种状态。 然后使用其id向频道发送消息

@client.event
async def on_member_update(before, after):
    if before.status is discord.Status.offline and after.status is discord.Status.online:
        print('was offline then online')
        channel = client.get_channel(ID_HERE)  # notification channel
        await channel.send(f'{after.name} is now {after.status}')

文档:

discord.Status

暂无
暂无

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

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