python - 不和谐.py : How do I get the name of the user who triggers on_member_update?

标签 python

async def on_member_update(before, after):
    print(str(after.username))
    if str(after.username) == "example username" # I'm looking for something like this
        print(str(af`enter code here`ter.username))
    if str(before.status) == "online":
        if str(after.status) == "offline":
            print("offline")
    elif str(before.status) == "offline":
        if str(after.status) == "online":
            print("online")
那么我怎样才能让它显示哪个用户触发了这个事件呢?

最佳答案

beforeafter是成员对象,因此您可以轻松地从那里获取成员名称。
你的代码应该是这样的:

async def on_member_update(before, after):

    member = bot.get_guild(before.guild.id).get_member(before.id)
    print(member.name)

    if str(member.name) == "example username" 
        print(member.name)

    if str(before.status) == "online":
        if str(after.status) == "offline":
            print("offline")

    elif str(before.status) == "offline":
        if str(after.status) == "online":
            print("online")

关于python - 不和谐.py : How do I get the name of the user who triggers on_member_update?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67798670/

相关文章:

python - 使用 if 语句确定 for 循环范围 - pandas.append 在循环中不起作用

Python在另一个cmd窗口中重启脚本

python - 为什么可以针对元组而不是列表进行格式化?

仅使用不记名 token 的 Python gRPC 客户端请求

python - 如何注释插入式钩子(Hook)规范的类型?

python - 不将 **kwargs 从自定义 View /表单传递给 django-import-export 资源

python - Azure Databricks 中的多重处理

python - 从具有重复键 Python 的字符串创建一个 dict/json

python - 从 .ui 访问元素

Python:合并嵌套列表