python - 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))
这似乎不起作用。
解决方案
您必须比较两种状态。然后使用其向通道发送消息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}')
文件:
推荐阅读
- node.js - 由于安全限制: browserWindow 未定义,是否有任何替代方案
- codeigniter - 什么相当于 $from_email = _REG_EMAIL_; 在 Codeigniter 4 中?
- machine-learning - Ray每次迭代后的渲染环境?
- javascript - 使用 vanilla javascript 在 HTML 表格行中动态添加按钮
- while-loop - 如何将 RFID 和超声波距离传感器中的多进程写入一个脚本?
- python - 当我的 python 休息客户端运行时,减少弹性搜索中 jvm 的使用
- python - Sharepoint excel 数据无需下载即可进入 Pandas 数据框
- vue.js - 在 vue 项目中卸载后如何取这个
- sql - 在我的情况下如何将字符串与变量连接起来
- java - 新建一个 Frame 实例而不是创建一个类实例导致了问题