nisico2603
nisico2603

Reputation: 31

Modifying timestamp in discord.py

I am making a giveaway command for myself, but I can't figure out how to display the end time of the giveaway as an embed timestamp, could anyone help? I read through the embed docs but that did not really help, maybe I am stupid, but I cant figure it out.

@bot.command()
async def giveaway(ctx, timer=None):

    if not timer:
        await ctx.send(f"only use #s for seconds. #m for minutes. #h for hours. #d for days. ")
        return

    if '.' not in timer:
        time_in_sec = 0
        if (timer[-1] == 'h') and (timer.count('h') == 1):
            time_in_sec = int(timer[:-1]) * 3600
            type__ = 'hour'
        elif (timer[-1] == 'm') and (timer.count('m') == 1):
            time_in_sec = int(timer[:-1]) * 60
            type__ = 'minute'
        elif (timer[-1] == 's') and (timer.count('s') == 1):
            time_in_sec = int(timer[:-1])
            type__ = 'second'
        elif (timer[-1] == 'd') and (timer.count('d') == 1):
            time_in_sec = int(timer[:-1]) * 86400
            type__ = 'day'
        elif timer.isdigit():
            time_in_sec = int(timer)
        else:
            await ctx.send(f"only use #s for seconds. #m for minutes. #h for hours. #d for days. ")
            return

        await ctx.message.delete()

        timestamp = time.time()
        embed = discord.Embed(
            title=f"TIMESTAMP TEST",
            timestamp=(datetime.datetime.utcfromtimestamp(timestamp)),
            color=0x40a0c6,
            description=f"**starting giveaway of {timer} {type__}(s)**'")
        embed.set_footer(text='__footer__')
        await ctx.send(embed=embed)

        await asyncio.sleep(time_in_sec)

        embed = discord.Embed(
            title=f"TIMESTAMP TEST",
            timestamp=(datetime.datetime.utcfromtimestamp(timestamp)),
            color=0x40a0c6,
            description=f"**giveaway of {timer} {type__}(s) is over!**")
        embed.set_footer(text='__footer__')
        await ctx.send(embed=embed)
    else:
        await ctx.send('**numbers only work**')

Upvotes: 2

Views: 1820

Answers (2)

nisico2603
nisico2603

Reputation: 31

I figured it out. Thanks for the help @FluxedScript!

this also helped

timestamp = time.time() + time_in_sec
    embed = discord.Embed(
        title=f"TIMESTAMP TEST",
        timestamp=(datetime.datetime.utcfromtimestamp(timestamp)),
        color=0x40a0c6,
        description=f"**starting giveaway of {timer} {type__}(s)**'")
    embed.set_footer(text='Giveaway Ends')
    await ctx.send(embed=embed)

Upvotes: 0

Axisnix
Axisnix

Reputation: 2907

You will have to use Embed.timestamp

import datetime
    embed = discord.Embed(
        title=f"TIMESTAMP TEST",
        timestamp=(datetime.datetime.utcfromtimestamp(timestamp)),
        color=0x40a0c6,
        description=f"**starting giveaway of {timer} {type__}(s)**'")
    embed.set_footer(text='__footer__')
    embed.timestamp = datime.datetime.now() + datetime.timedelta(hours=23,minutes=59)
    await ctx.send(embed=embed)

Upvotes: 2

Related Questions