Reputation: 33
Trying to make a discord command to show the amount of time my daughter has been alive
@commands.command(hidden=True)
@commands.cooldown(1, 5, commands.BucketType.guild)
async def luxe(self, ctx):
currentDate = datetime.utcnow()
print(currentDate)
deadline = '08/05/2020 10:05:00'
deadlineDate = datetime.strptime(deadline, '%d/%m/%Y %H:%M:%S')
print(deadlineDate)
daysLeft = currentDate-deadlineDate
years = ((daysLeft.total_seconds()) / (365.242 * 24 * 3600))
yearsInt = int(years)
months = (years - yearsInt) * 12
monthsInt = int(months)
weeks = (years - yearsInt) * 52
weeksInt = int(weeks)
days = (months - monthsInt) * (365.242 / 12)
daysInt = int(days)
hours = (days - daysInt) * 24
hoursInt = int(hours)
minutes = (hours - hoursInt) * 60
minutesInt = int(minutes)
seconds = (minutes - minutesInt) * 60
secondsInt = int(seconds)
if yearsInt == 0 and monthsInt == 0:
embed = discord.Embed(title="Luxe Olivia Violet Ellisdon",
description=f"She is exactly {weeksInt} weeks, {daysInt} days, {hoursInt} hours, {minutesInt} minutes, {secondsInt} seconds old.",
colour=ctx.author.colour,
timestamp=datetime.utcnow())
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
embed.set_footer(text=f'You found an easter egg')
embed.set_image(url='https://i.ibb.co/M1kb2q0/100868516-10158119041366257-6490464808603746304-n.jpg')
await ctx.send(embed=embed)
elif yearsInt == 0:
embed = discord.Embed(title="Luxe Olivia Violet Ellisdon",
description=f"She is exactly {monthsInt} months, {weeksInt} weeks, {daysInt} days, {hoursInt} hours, {minutesInt} minutes, {secondsInt} seconds old.",
colour=ctx.author.colour,
timestamp=datetime.utcnow())
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
embed.set_image(url='https://i.ibb.co/M1kb2q0/100868516-10158119041366257-6490464808603746304-n.jpg')
embed.set_footer(text=f'You found an easter egg')
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="Luxe Olivia Violet Ellisdon",
description=f"she is exactly {yearsInt} years, {monthsInt} months, {weeksInt }weeks, {daysInt} days, {hoursInt} hours, {minutesInt} minutes, {secondsInt} seconds old.",
colour=ctx.author.colour,
timestamp=datetime.utcnow())
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
embed.set_image(url='https://i.ibb.co/M1kb2q0/100868516-10158119041366257-6490464808603746304-n.jpg')
embed.set_footer(text=f'You found an easter egg')
await ctx.send(embed=embed)
its not quite right and I don't understand why and I would love if someone could explain what it is I am doing wrong. Ived added an edit to it due to the sum being the wrong way around and the deadline being the wrong way around
Upvotes: 1
Views: 168
Reputation:
Maybe this function will help you:
def convert_timedelta(duration):
days, seconds = duration.days, duration.seconds
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 60)
return days, hours, minutes, seconds
Example:
# Your code
currentDate = datetime.utcnow()
deadline = '08/05/2020 10:05:00'
deadlineDate = datetime.strptime(deadline, '%d/%m/%Y %H:%M:%S')
daysLeft = currentDate - deadlineDate
days, hours, minutes, seconds = convert_timedelta(daysLeft) # Use function
print('Days left:', days,
'\nHours left:', hours,
'\nMinutes left:', minutes,
'\nSeconds left:', seconds)
Output:
Days left: 42
Hours left: 7
Minutes left: 47
Seconds left: 44
And then you can use variables days, hours, minutes, seconds
in your Embed, how you want.
Upvotes: 1