#Reminder Command String Duration
1 messages · Page 1 of 1 (latest)
here's the code:
# @commands.slash_command(name="remind-me", description="Set a reminder")
# async def reminder(
# self,
# ctx,
# duration: str,
# reminder: Option(str, description="What's the reminder for?"),
# ):
duration_dict = {"d": 0, "h": 0, "m": 0, "s": 0}
for letter, value in re.findall(r"(\D)(\d+)", duration):
duration_dict[letter] = int(value)
reminder_time = datetime.now() + timedelta(
days=duration_dict["d"],
hours=duration_dict["h"],
minutes=duration_dict["m"],
seconds=duration_dict["s"],
)
epoch_time = reminder_time.timestamp()
# embed1 = discord.Embed(
# title=f"Reminder Set",
# description=f"A reminder has been set for <t:{round(epoch_time)}:f>\n\n**Reminder:** {reminder}",
# color=0x4B8FCA,
# )
# embed1.set_author(icon_url=ctx.author.avatar.url, name=ctx.author)
# await ctx.respond(embed=embed1)
await asyncio.sleep((reminder_time - datetime.now()).total_seconds())
# embed2 = discord.Embed(
# title="⏰ Reminder!", description=f"{reminder}", color=0x4B8FCA
# )
# await ctx.send(embed=embed2, content=ctx.author.mention)
There is a cool library called time_str which converts human readable string to a timedelta object
If i wanted to make changes to this function and not use that library, i would change the regex to
(\d+)([dhms])
Haven't checked the regex so try it and see
Done with your help thread?
Please close your own help thread by using </close:1009144375709814897> with @real ginkgo.
Oh sorry, forgot to reply to your old message. But um yeah, I do. The regex I tried didn’t work
And I don’t think I can use the time_str library because it doesn’t support Python 3.11
no? it works. i use it myself on 3.11
well what didnt work?
have you tried a regex tester?
Oh? I’m not too sure then, I installed it but I couldn’t import it
I’ll get the error, one sec
you might be having python environment issues.
do you use venv?
I don't think so
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: ValueError: invalid literal for int() with base 10: 'd'
ah
well you are using groups
so split it out
btw i updated the regex
wdym? like put a space between the integer and letter?
Python regex capturing groups match several distinct patterns inside the same target string using group() and groups()
it might be difficult to understand at first but read the whole thing
alright, I just finished, and now I understand the regex you gave earlier
and I was able to fix the issue, I think, testing right now
yeah I did
thank you so much :)
have a good night
Cool
.close
Done with your help thread?
Please close your own help thread by using </close:1009144375709814897> with @real ginkgo.