0

I want to make a moderating bot that kicks alt accounts (accounts that are younger than 10 days)I have whois command but it only shows when account was created:

@client.command(name="whois", aliases=["memberinfo"])
async def whois(ctx, member:discord.Member =  None):

    

    if member is None:
        member = ctx.author
        roles = [role for role in ctx.author.roles]

    else:
        roles = [role for role in member.roles]

    embed = discord.Embed(title=f"{member}", colour=member.colour, timestamp=ctx.message.created_at)
    embed.set_footer(text=f"Requested by: {ctx.author}", icon_url=ctx.author.avatar_url)
    embed.set_author(name="User Info: ")
    embed.add_field(name="ID:", value=member.id, inline=False)
    embed.add_field(name="User Name:",value=member.display_name, inline=False)
    embed.add_field(name="Discriminator:",value=member.discriminator, inline=False)
    embed.add_field(name="Current Status:", value=str(member.status).title(), inline=False)
    embed.add_field(name="Current Activity:", value=f"{str(member.activity.type).title().split('.')[1]} {member.activity.name}" if member.activity is not None else "None", inline=False)
    embed.add_field(name="Created At:", value=member.created_at.strftime("%a, %d, %B, %Y, %I, %M, %p UTC"), inline=False)
    embed.add_field(name="Joined At:", value=member.joined_at.strftime("%a, %d, %B, %Y, %I, %M, %p UTC"), inline=False)
    embed.add_field(name=f"Roles [{len(roles)}]", value=" **|** ".join([role.mention for role in roles]), inline=False)
    embed.add_field(name="Top Role:", value=member.top_role, inline=False)
    embed.add_field(name="Bot?:", value=member.bot, inline=False)

    await ctx.send(embed=embed)
    return

How can I make something like:

if member < 10 days:
    await member.kick
    await channel.send('Detected alt account and kicked it')

I also don't want full code. I need only explanation how to do this. Thank you

Matan Ka.
  • 273
  • 1
  • 2
  • 13

2 Answers2

2

discord.Member has the attribute created_at which returns a datetime.datetime instance, you can get the delta days by subtracting today's date and using the days attribute

created = member.created_at
now = datetime.now() # remember to `from datetime import datetime`
delta = (now - created).days

if delta < 10:
    await member.kick()
    await channel.send('Detected alt account and kicked it')

Reference:

Łukasz Kwieciński
  • 14,992
  • 4
  • 21
  • 39
1

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.created_at
datetime.datetime(2013, 8, 6, 14, 22, 14)

Then you could simply take another datetime object for now and substract one from the other:

import datetime as datetime
now = datetime.datetime.now()
if (now - myaccount.created_at).days > 10
    await member.kick()
    await channel.send('Detected alt account and kicked it')
Shunya
  • 2,344
  • 4
  • 16
  • 28