如何让我的静音命令告诉用户静音何时到期?不和谐.py
我目前正在更新我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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:我的功能可以进行转换。
然后,您可以通过执行此类操作(对您喜欢的调整)进行转换:
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>
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.
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'