【问题标题】:Discord.py check member statusDiscord.py 检查会员状态
【发布时间】:2021-03-14 01:04:49
【问题描述】:

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

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

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

这似乎不起作用。

【问题讨论】:

  • Aghgh 格式不太好,请想象每个冒号后都有适当的缩进。
  • 提示:您可以通过点击问题下方的编辑按钮来编辑您的问题

标签: python discord bots discord.py


【解决方案1】:

您必须比较两种状态。然后使用其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

【讨论】:

  • 我已经尝试过了,但似乎无法正常工作:(不过感谢您的帮助!
  • 它应该按原样工作,您遇到什么错误?从文档中记住这一点This requires Intents.members to be enabled.
  • 是的,我调查了它并需要更改意图。谢谢!
  • 很高兴它成功了,如果是,请将其标记为答案。
猜你喜欢
  • 2018-11-23
  • 2021-07-09
  • 1970-01-01
  • 1970-01-01
  • 2021-07-15
  • 1970-01-01
  • 2021-02-03
  • 2021-02-02
  • 1970-01-01
相关资源
最近更新 更多