首页 > 解决方案 > Discord.py 检查会员状态

问题描述

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

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

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

这似乎不起作用。

标签: pythondiscordbotsdiscord.py

解决方案


您必须比较两种状态。然后使用其向通道发送消息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


推荐阅读