1

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

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

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

这似乎不起作用。

4

1 回答 1

2

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

于 2020-12-02T05:35:10.910 回答