【发布时间】:2021-08-23 04:28:20
【问题描述】:
我的机器人是为一台服务器制作的,我想在某个用户(机器人)下线时向特定频道发送消息,我该怎么做?
【问题讨论】:
标签: discord.py
我的机器人是为一台服务器制作的,我想在某个用户(机器人)下线时向特定频道发送消息,我该怎么做?
【问题讨论】:
标签: discord.py
首先,检测是否有成员更新,为此您必须启用intents.members,如this post 中所述。
检测会员更新,有事件on_member_update:
@bot.event #could be client.event for you
async def on_member_update(before, after):
然后,检查更新的人是否是应该寻找的人:
user = await bot.fetch_user(user_id_of_user_to_look_for) #could be client.fetch_user for you
if user == after:
然后检查状态是否变为离线:
if before.status != discord.Status.offline and after.status == discord.Status.offline:
然后向频道发送消息,其中channel是您要将消息发送到的频道的频道对象:
await channel.send("User went offline")
【讨论】: