diff --git a/telegram/ext/_commandhandler.py b/telegram/ext/_commandhandler.py index 02cf6152d..5a762ba80 100644 --- a/telegram/ext/_commandhandler.py +++ b/telegram/ext/_commandhandler.py @@ -97,7 +97,7 @@ class CommandHandler(Handler[Update, CCT]): self.command = [x.lower() for x in command] for comm in self.command: if not re.match(r'^[\da-z_]{1,32}$', comm): - raise ValueError('Command is not a valid bot command') + raise ValueError(f'Command `{comm}` is not a valid bot command') self.filters = filters if filters is not None else filters_module.UpdateType.MESSAGES diff --git a/tests/test_commandhandler.py b/tests/test_commandhandler.py index 5dbf8005b..d2622e892 100644 --- a/tests/test_commandhandler.py +++ b/tests/test_commandhandler.py @@ -173,7 +173,9 @@ class TestCommandHandler(BaseTest): ids=['too long', 'invalid letter', 'invalid characters'], ) def test_invalid_commands(self, cmd): - with pytest.raises(ValueError, match='not a valid bot command'): + with pytest.raises( + ValueError, match=f'`{re.escape(cmd.lower())}` is not a valid bot command' + ): CommandHandler(cmd, self.callback_basic) def test_command_list(self):