所以,我尝试使用discord.py 创建一个提醒功能。这是我的代码:
@client.command(name = "reminder", brief = "I'll send a message to the future.",
description = "State what I have to remind you, as well as when and in which channel and I'll do it! "
"Write d for days, h for hours, m for minutes and s for seconds after the number and then "
"what you want to be remided of. For example: >reminder 1h 30m eat chocolate",
aliases = ["remind", "remindme", "remindto"])
async def reminder(ctx, time, *, reminder):
user = ctx.message.author
seconds = 0
if reminder is None:
ctx.send("Please, tell me what you want me to remind you about!")
if time.lower().endswith("d"):
seconds += float(time[:-1]) * 60 * 60 * 24
counter = f"{seconds // 60 // 60 // 24} days"
if time.lower().endswith("h"):
seconds += float(time[:-1]) * 60 * 60
counter = f"{seconds // 60 // 60} hours"
if time.lower().endswith("m"):
seconds += float(time[:-1]) * 60
counter = f"{seconds // 60} minutes"
if time.lower().endswith("s"):
seconds += float(time[:-1])
counter = f"{seconds} seconds"
if seconds == 0:
await ctx.send("You can't tell me that!")
else:
await ctx.send(f"Alright, I will remind you about {reminder} in {counter}.")
await asyncio.sleep(seconds)
await ctx.send(f"Hi, <@{user.id}>, you asked me to remind you about {reminder} {counter} ago.")
return
我的问题是,当有人为“时间”写出多个论点时,我不知道如何使其发挥作用。例如,如果我调用该函数>reminder 1h 30min eat chocolate,它会在 1 小时内提醒我“30 分钟吃巧克力”,而不是在 1 小时 30 分钟内提醒我。我不知道是否有办法解决这个问题(除了写1.5h)。任何输入都会有用。多谢!
白板的微信
慕村225694
相关分类