'How do I make my mute command tell the user when their mute expires? discord.py

I'm currently updating my tempmute command, and I have this code here:

time_convert = {"s":1, "m":60, "h":3600,"d":86400}
tempmute= int(time[:-1]) * time_convert[time[-1]]
current_time = datetime.datetime.utcnow()
final_time = current_time + datetime.timedelta(seconds=tempmute)

It does work, however it displays as Year/Month/Day Hour/Minutes/Seconds/some other numbers. (I assume because this hasn't been rounded)

I would rather have it display as "Name of the day, number of the day, month, year, hour, minutes. So for example: Thu, 07 Apr 2022 04:30PM

I have tried things such as

mute_expires = current_time + datetime.timedelta(seconds=tempmute)
mute_expires = datetime.timedelta.strftime("%a, %d %b %Y %I:%M %p UTC")

But it gives me an error: Command raised an exception: AttributeError: type object 'datetime.timedelta' has no attribute 'strftime'. I have tried things similar to this and got similar errors. I know it sounds stupid but I thought I would ask as I'm so confused.

Thanks.

Is there anyway to do this?

Another thing I wanted to add on: I have this cooldown code:

ef better_time(self, cd:int):
        time = f"{cd} seconds"
        if cd > 60:
            minutes = cd - (cd % 60)
            seconds = cd - minutes
            minutes = int(minutes/ 60)
            time = f"{minutes} minutes"# {seconds} second(s)"
            if minutes > 60:
                hoursglad = minutes -(minutes % 60)
                hours = int(hoursglad/ 60)
                minutes = minutes - (hours*60)
                time = f"{hours} hours" #{minutes} minute(s) {seconds} second(s)"
        return time```

How would I go about to doing days? 


Solution 1:[1]

Datetime does not work well for this, but you can use the timestamp formatter: https://discord.com/developers/docs/reference#message-formatting-formats. This makes it better because it respects the locale of the user it's being displayed to. They follow the format <t:UNIX_TIME_123456789:FORMAT_SPECIFIER_YOU_CAN_FIND_IN_THE_DOCS>

timestamps

In particular, the F format matches what you want to do, you can use it by saying <t:1:F> in the message.

Sidenote: I have a function that does the converting.

# input things like 1d, 1h30m, 2m30s, or 6d23h59m59s
def parse_timestamp(stringtime):
    time_days = 0
    time_hours = 0
    time_minutes = 0
    time_seconds = 0
    if 'd' in stringtime:
        time_days, stringtime = int(stringtime.partition('d')[0]), stringtime.partition('d')[2]
    if 'h' in stringtime:
        time_hours, stringtime = int(stringtime.partition('h')[0]), stringtime.partition('h')[2]
    if 'm' in stringtime:
        time_minutes, stringtime = int(stringtime.partition('m')[0]), stringtime.partition('m')[2]
    if 's' in stringtime:
        time_seconds, stringtime = int(stringtime.partition('s')[0]), stringtime.partition('s')[2]
    return 86400*time_days + 3600*time_hours + 60*time_minutes + time_seconds


You can then convert back by doing something like this (tweak to your liking): f'{m_time // 86400}d {(m_time // 3600) % 24}h {(m_time // 60) % 60}m {m_time % 60}s'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric Jin