如何在 discord.py 中查看用户的创建日期? [英] How to check the creation date of an user in discord.py?
本文介绍了如何在 discord.py 中查看用户的创建日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查用户加入时的帐户是否超过 30 天(on_member_join
).如果不是,机器人应该向频道发送消息.我对如何检查帐户的年龄"有疑问.
I want to check if the a user's account is more than 30 days old when he joins (on_member_join
). If it's not the bot should send a message to a channel. I have problems how to check the account's "age".
有人有想法吗?
推荐答案
从 discord.py
文档中,您可以使用 discord 的
或 created_at
属性.Userdiscord.Member
类.它将返回一个 datetime.datetime
对象.
From the discord.py
documentation, you can use the created_at
attribute of a discord.User
or discord.Member
class. It will return a datetime.datetime
object.
>>> myaccount = client.get_user(my_id)
>>> myaccount.created_at
datetime.datetime(2013, 8, 6, 14, 22, 14)
>>> myaccount.timestamp()
1375813334.0
>>> time.time() - myaccount.timestamp() > 2592000 # 2592000 seconds is 30 days
True
您可以将其合并到 on_member_join
客户端事件中.
You can incorporate this into an on_member_join
client event.
@client.event
async def on_member_join(member):
if time.time() - member.created_at.timestamp() < 2592000:
# do stuff if the account is young #
else:
# do stuff if the account is not young #
这篇关于如何在 discord.py 中查看用户的创建日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文