简体   繁体   English

Python Discord - 如何获取特定服务器中成员的初始加入日期?

[英]Python Discord - How to get the initial joined date for a member in a specific server?

For the past few months I have been working on a discord bot in a server I am moderating.在过去的几个月里,我一直在我正在主持的服务器中研究 discord 机器人。 I started with no experience in discord bots so I chose python over javascript when I started with my bot.我一开始没有 discord 机器人的经验,所以当我开始使用我的机器人时,我选择了 python 而不是 javascript。 I am rather familiar with the discord library in python and have been able to use it for almost everything that has been needed so far.我对 python 中的 discord 库非常熟悉,并且能够将它用于迄今为止所需的几乎所有内容。

I am in a need to get the date when a user joined my server for the first time.我需要获取用户第一次加入我的服务器的日期。 In the documentation it states:在文档中它指出:

joined_at: A datetime object that specifies the date and time in UTC that the member joined the guild. join_at:日期时间 object,指定成员加入公会的 UTC 日期和时间。 If the member left and rejoined the guild, this will be the latest date .如果成员离开并重新加入公会,这将是最晚的日期

I am wondering if it is at all possible to get the date when a user joined a server for the first time using the pythons discord library?我想知道是否有可能使用 pythons discord 库获取用户第一次加入服务器的日期? Is discord even keeping track of this? discord 甚至会跟踪这个吗? It would be really nice, if I could get this information without having to log it on my own.如果我无需自己登录就能获得这些信息,那就太好了。

Assuming you are using discord py isn't keeping the first joined date.假设您使用的是 discord py 并没有保留第一个加入日期。 However, you can save the first joined date within a dictionary or a database.但是,您可以将第一个连接日期保存在字典或数据库中。

Example for saving in a dictionary保存在字典中的示例


def __init__(self, client):
    self.client = client
    self.first_join = {}

@commands.Cog.listener()
async def on_member_join(self, member):
    if member in first_join:
        return

    self.first_join[member.id] = member.joined_at

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM