diff options
author | 2023-03-03 14:52:20 +0200 | |
---|---|---|
committer | 2023-03-03 14:52:20 +0200 | |
commit | a6626d28b753882ab2a711d3dee46d44636b1fa3 (patch) | |
tree | 255da2ab22a308a8c4f86e7529ee4b5d7750ac90 | |
parent | Merge pull request #2421 from shtlrs/bump-pydis-core-to-9-5-0 (diff) | |
parent | Merge branch 'main' into trim-help-command-error-title (diff) |
Merge pull request #2380 from python-discord/trim-help-command-error-title
Trim query in command not found error to avoid embed limits
-rw-r--r-- | bot/exts/info/help.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/bot/exts/info/help.py b/bot/exts/info/help.py index 48f840e51..8950f4936 100644 --- a/bot/exts/info/help.py +++ b/bot/exts/info/help.py @@ -244,15 +244,20 @@ class CustomHelpCommand(HelpCommand): choices.update(cog.category for cog in self.context.bot.cogs.values() if hasattr(cog, "category")) return choices - async def command_not_found(self, string: str) -> "HelpQueryNotFound": + async def command_not_found(self, query: str) -> "HelpQueryNotFound": """ Handles when a query does not match a valid command, group, cog or category. Will return an instance of the `HelpQueryNotFound` exception with the error message and possible matches. """ choices = list(await self.get_all_help_choices()) - result = process.extract(default_process(string), choices, scorer=fuzz.ratio, score_cutoff=60, processor=None) - return HelpQueryNotFound(f'Query "{string}" not found.', {choice[0]: choice[1] for choice in result}) + result = process.extract(default_process(query), choices, scorer=fuzz.ratio, score_cutoff=60, processor=None) + + # Trim query to avoid embed limits when sending the error. + if len(query) >= 100: + query = query[:100] + "..." + + return HelpQueryNotFound(f'Query "{query}" not found.', {choice[0]: choice[1] for choice in result}) async def subcommand_not_found(self, command: Command, string: str) -> "HelpQueryNotFound": """ |