简体   繁体   English

Discord.py 查看会员状态

[英]Discord.py check member status

I am trying to write a chunk of code for my discord bot that announces when one of my friend's profile status updates from offline to online.我正在尝试为我的 discord 机器人编写一段代码,当我朋友的个人资料状态从离线更新为在线时,它会发出通知。

Currently, I am fiddling around with some code, this is what I have so far:目前,我正在摆弄一些代码,这是我目前所拥有的:

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

This doesn't seem to be working.这似乎不起作用。

You have to compare both status.您必须比较两种状态。 then send a message to a channel using its id然后使用其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}')

Docs:文档:

discord.Status

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

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