#Reminder Command String Duration

1 messages · Page 1 of 1 (latest)

signal slate
#

Hey so I'm making a reminder command for my bot, and it takes a string option which takes an integer and a letter for the duration, but the issue is that it takes the string as the following format; "s30", instead of the letter behind the integer.

#

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)
fallen hatch
#

There is a cool library called time_str which converts human readable string to a timedelta object

fallen hatch
#

Haven't checked the regex so try it and see

fallen hatch
#

@signal slate do you still need help?

#

.close

solemn birchBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @real ginkgo.

signal slate
#

And I don’t think I can use the time_str library because it doesn’t support Python 3.11

fallen hatch
fallen hatch
#

have you tried a regex tester?

signal slate
signal slate
fallen hatch
#

do you use venv?

signal slate
#

I don't think so

signal slate
fallen hatch
#

ah

#

well you are using groups

#

so split it out

#

btw i updated the regex

signal slate
fallen hatch
#

it might be difficult to understand at first but read the whole thing

signal slate
#

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

solemn birchBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @real ginkgo.