79809618

Date: 2025-11-05 04:41:34
Score: 0.5
Natty:
Report link

The problem

As mentioned in the comments by Barmar, an attempt to put things into the positional argument of time when there are multiple spaces moves it to the reason.

+t @user 3d2h1s30m test

The solution

Regex works

A simple fix could be the way that you run the command itself: without spaces fix

As long as the time duration is without spaces, your regex works perfectly!

Using quotes

+t @Nestling Bot#9410 "3d 2h 1s 30m" test

using quotes Like Barmar mentioned, quotes work just fine.

Making one argument and parsing through it (probably what you want)

Another way to do this is to have one keyword positional argument that parses until the last segment of hour/minute/second/day:

@bot.command(
    name="timeout",
    aliases=["mute", "t"],
    help=""
)
@has_permissions(moderate_members=True)
async def timeout(ctx, user: discord.Member, *, reasonAndTime="No reason provided"):

    print(reasonAndTime)

    # this is an odd way to go about things but hey it should work right?
    time = ''
    reason = ''
    for param in reasonAndTime.split(' '):
        try:
            if param[-1] == 's':  # check seconds
                time += param
            elif param[-1] == 'm':  # check seconds
                time += param
            elif param[-1] == 'h':  # check seconds
                time += param
            elif param[-1] == 'd':  # check seconds
                time += param
            else:
                reason += f' {param}'
        except TypeError:  # Not an int, see https://stackoverflow.com/a/3501408/15982771
            reason += f' {param}'

Timeout based on positional

Resources

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: Blue Robin