'(Discord Py) How to make a command that checks a user's account date

I want to have a command that when I say %alt <@user>, it would tell me the age of the account and if it is less than a week old, it says "Alt Found". Any way to do this?



Solution 1:[1]

I'm pretty sure you could do something like this

@bot.command()
async def CreatedAccountAt(self,ctx):
   await ctx.send(ctx.author.created_at)

You can also add some of your own logic in to the method to work out if to send the 'Alt Found' message at the end

Solution 2:[2]

You can do something like this:

import datetime, discord

@client.event
def on_message(message: discord.Message):
    if message.content.lower().startswith("%alt"):
        target = await client.fetch_user(int(message.content.lower().replace("%alt ").replace("<","").replace(">","").replace("@","").replace("!","")[:18]))
        if float((datetime.datetime.now() - target.created_at).total_seconds()) < 2.628e+6:
            await message.reply("Alt Found!", mention_author=False)
        else:
            await message.reply("Not an alt", mention_author=False)

Note that 2.628e+6 represents amount of seconds in a month in a scientific notation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TryingMahBest
Solution 2 Y?lmaz Alpaslan