如何让我的静音命令告诉用户静音何时到期?不和谐.py

发布于 2025-01-20 04:55:07 字数 1285 浏览 1 评论 0原文

我目前正在更新我的tempmute命令,并且在此处有此代码:

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)

它确实有效,但是它显示为年/月/天/天/分钟/秒/其他一些数字。 (我认为这是因为尚未四舍五入)

我宁愿将其显示为“每日的名称,每日,月,年,小时,几分钟

。尝试了诸如此类的事情

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

,但它给了我一个错误:命令提出了一个例外:attributeError:type object'dateTime.timedelta'没有属性'strftime'。错误

​ 我有此冷却代码:

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? 

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? 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2025-01-27 04:55:08

DateTime不能很好地工作,但是您可以使用时间戳格式: https:> https:> https: //discord.com/developers/docs/reference#message-formatting-formats 。这使它变得更好,因为它尊重正在展示的用户的网站。他们遵循格式< t:unix_time_123456789:format_specifier_you_can_find_find_in_the_the_dthe_dthe_docs>

f格式匹配您想做的事情,您可以通过说出它来使用它< t:1:f>在消息中。

Sidenote:我的功能可以进行转换。

# 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


然后,您可以通过执行此类操作(对您喜欢的调整)进行转换:f'{m_time // 86400} d {(M_Time // 3600)%24} h {(M_Time // 60)60} m {m_time%60} s'

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'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文