Home > Blockchain >  How to send when an event has ended in discord.py
How to send when an event has ended in discord.py

Time:11-20

I am trying to get an output like this, in which it tells when the message was sent

enter image description here

I successfully got when a message was sent

    emb = discord.Embed(title=f"**{title}**", description=f"<:854745395314163784:910908229897297940> Ends in {lenght}")
    emb.set_thumbnail(url='https://images-ext-2.discordapp.net/external/D14-NqrYBiv91a8nM8tVD4b0SuN-CAUlmooEq0dtWsM/https/kaj.gg/r/kq902alos9a.png?width=80&height=80')
    emb.set_footer(text = f"{winners} Winner")
    msg_2 = await ctx.send(embed=emb)
    await msg_2.add_reaction(emoji)
    id = msg_2.id
    created = msg_2.created_at
    print(created)

Here is the output

but I cant figure out how to return a message like "Ended a Few seconds ago" or "Ended few hours ago"

CodePudding user response:

The example you sent uses Discord's built-in timestamp format, outlined here. You can obtain a Unix timestamp by using datetime's timestamp() function on msg_2.created_at, something like this for your example:
f"<t:{int(msg_2.created_at.replace(tzinfo=datetime.timezone.utc).timestamp())}:R>"
You can then include that string in a message normally.

  • Related