Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在discord.py中识别用户_Python_Python 3.x_Discord.py - Fatal编程技术网

Python 如何在discord.py中识别用户

Python 如何在discord.py中识别用户,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,您好,我正在使用on_member_update(before,after)事件引用查看discord服务器的管理员和版主何时联机和脱机以监视管理员活动。 到目前为止,我可以让我的程序告诉我有人在线和离线,以及在什么时候,但我无法确定哪个用户在线和离线,所以我得到如下信息: User: has come online at {current_time}. User: has come online at {current_time}. User: has come online at {curr

您好,我正在使用on_member_update(before,after)事件引用查看discord服务器的管理员和版主何时联机和脱机以监视管理员活动。 到目前为止,我可以让我的程序告诉我有人在线和离线,以及在什么时候,但我无法确定哪个用户在线和离线,所以我得到如下信息:

User: has come online at {current_time}.
User: has come online at {current_time}.
User: has come online at {current_time}.
User: has gone offline at {current_time}.
User: has gone offline at {current_time}.
User: has come online at {current_time}.
User: has gone offline at {current_time}.
User: has gone offline at {current_time}.
所以我不知道谁在上网,谁在下线,所以据我所知,一次又一次是同一个人。由于on_member_update()事件引用中没有成员参数,如何识别成员/用户。 如果您需要任何澄清,请询问。 谢谢

这是我的密码:

@client.event
async def on_member_update(before, after):
    current_time = datetime.datetime.now()
    if str(after.status) == 'offline':
        print(f'User: has gone offline at {current_time}.'.format(after.name, after.status))
    if str(after.status) == 'online':
        print(f'User: has come online at {current_time}.'.format(after.name, after.status))

之后的
已经是成员对象,如果要获取名称,只需添加
.name

if str(after.status) == 'offline':
    print(f'{after.name}: has gone offline at {current_time}.'.format(after.name, after.status))
if str(after.status) == 'online':
    print(f'{after.name}: has come online at {current_time}.'.format(after.name, after.status)) 

# Output: JohnSmith: has gone offline at some_time.
# Output: JohnSmith: has gone online at some_time.
如果您也希望获得#号码,您可以使用以下选项:

if str(after.status) == 'offline':
    print(f'{after.name}#{after.discriminator}: has gone offline at {current_time}.'.format(after.name, after.status))
if str(after.status) == 'online':
    print(f'{after.name}#{after.discriminator}: has come online at {current_time}.'.format(after.name, after.status)) 

# Output: JohnSmith#1234: has gone offline at some_time.
# Output: JohnSmith#1234: has gone online at some_time.
  • 之前(用户)–更新后用户的旧信息。

  • 之后(用户)–更新用户的更新信息。


您可以找到有关
on_member\u update
事件的完整文档以及
discord.User
对象的完整文档。

是否要使用上述数据检查用户是联机还是脱机?两者都有,你想让我给你看代码吗?它基本上检查后状态是否与前不同,后状态是否更改为脱机或联机,它告诉我你有
后。名称
,但你不使用它。我需要找到的是如何识别用户,例如在on_消息引用中,你可以只执行message.author to识别用户