修改 discord.py 中的时间戳
Modifying timestamp in discord.py
我正在为自己制作赠品命令,但我不知道如何将赠品的结束时间显示为嵌入时间戳,有人可以帮忙吗?我通读了 embed 文档,但这并没有真正帮助,也许我很愚蠢,但我无法弄清楚。
@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**')
您将不得不使用 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)
我明白了。感谢帮助@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)
我正在为自己制作赠品命令,但我不知道如何将赠品的结束时间显示为嵌入时间戳,有人可以帮忙吗?我通读了 embed 文档,但这并没有真正帮助,也许我很愚蠢,但我无法弄清楚。
@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**')
您将不得不使用 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)
我明白了。感谢帮助@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)