Search code examples
discorddiscord.pytimestamp

Discord.py: how to show dates in an embed like shown in discord message timestamps?


I want to replicate this representation of time: What I Want To Recreate

What I already have: What I Have

Code:

created = ctx.guild.created_at
embed.add_field(name = f"Created:", value = f"{created}", inline=False)

How can I recreate it?


Solution

  • So, discord uses epoch value to get time and the format to get it is <t:{epoch value}:{mode}>. To get the epoch value there is a function know as timestamp().

    So our new code will be :

    created = ctx.guild.created_at.timestamp()
    embed.add_field(name ="created at:", value=f"<t:{created}:R>",......)