I'm currently working on a discord bot that shows me user information like ID, Name, and that stuff, and I added a Join date and an account create date, they are working fine but I also want to include a "days ago" instead of the blank date.
Here is the code I have:
from unicodedata import name
import discord
from datetime import datetime
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='.',intents=intents)
@bot.event
async def on_ready():
print("Ready!")
@bot.command(name="user")
async def user(ctx,user:discord.Member=None):
if user==None:
user=ctx.author
rlist = []
for role in user.roles:
if role.name != "@everyone":
rlist.append(role.mention)
b = ','.join(rlist)
if rlist:
b = ','.join(rlist)
else:
b = "No roles"
embed = discord.Embed(colour=user.color,timestamp=ctx.message.created_at)
embed.set_author(name=f"User Info - {user}"),
embed.set_thumbnail(url=user.avatar.url),
embed.set_footer(text=f'Requested by - {ctx.author}',
icon_url=ctx.author.avatar.url)
embed.add_field(name='ID:' ,value=user.id,inline=False)
embed.add_field(name='Name:' ,value=user.display_name,inline=False)
embed.add_field(name='Created at:' ,value=datetime.strftime(user.created_at, "%#d/%m/%Y"), inline=False)
embed.add_field(name='Joined at:' ,value=datetime.strftime(user.joined_at, "%#d/%m/%Y"), inline=False)
embed.add_field(name='Bot?' ,value=user.bot,inline=False)
embed.add_field(name=f'Roles:({len(rlist)})',value=''.join([b]),inline=False)
embed.add_field(name='Top Role:' ,value=user.top_role.mention,inline=False)
await ctx.send(embed=embed)
I already tried
duration = dt.datetime.now() - user.joined_at
hours, remainder = divmod(int(duration .total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
days, hours = divmod(hours, 24)
await ctx.send(f"Joined before {days}d, {hours}h, {minutes}m, {seconds}s")
This one does not work, I think it has to do with the time zones, I tried to remove time zone awareness but that also did not work for me.