gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:46:57 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com