问题
To prevent new accounts from using a certain command, how could I get the age of a users account (or creation date) when they type a message.
client.get_user(account_date)
if account_date < 14:
print('Your account must be older than 14 days to use this command')
else:
print('Your account can use this command')
Any help is appreciated.
回答1:
You can get a User object from either ctx with ctx.author
or from a message with message.author
.
Then on the User object you can call created_at
.
So for example to get account of current user
@bot.command()
async def CreatedAccountAt(self,ctx):
await ctx.send(ctx.author.created_at)
or to get a user created date by ID
@bot.command()
async def CreatedAccountAt(ctx, userId: int):
user = bot.get_user(userId)
await ctx.send(user.created_at)
https://discordpy.readthedocs.io/en/latest/api.html#discord.User.created_at
来源:https://stackoverflow.com/questions/61611157/how-to-get-the-age-of-someones-account-discord-py