diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 4a07413d..9a1b2bdd 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -789,7 +789,7 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = " flags=re.IGNORECASE if not flt.case_sensitive else 0): continue - without_command = re.sub(rf"{cmd}(?:@?{username})?\s", "", without_prefix, count=1) + without_command = re.sub(rf"{cmd}(?:@?{username})?\s?", "", without_prefix, count=1) # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text diff --git a/tests/filters/test_command.py b/tests/filters/test_command.py index 0cd00e95..d9a7490e 100644 --- a/tests/filters/test_command.py +++ b/tests/filters/test_command.py @@ -103,6 +103,14 @@ async def test_with_mention(): async def test_with_args(): f = filters.command("start") + m = Message("/start") + await f(c, m) + assert m.command == ["start"] + + m = Message("/start@username") + await f(c, m) + assert m.command == ["start"] + m = Message("/start a b c") await f(c, m) assert m.command == ["start"] + list("abc")