diff options
author | 2023-01-14 19:01:47 +0000 | |
---|---|---|
committer | 2023-01-14 19:01:47 +0000 | |
commit | 7500eee5c16db9c580f2aa026f255645f7915e59 (patch) | |
tree | 9a8882170a3b2f8d31d3a3110c91abcb09fab08e | |
parent | Merge pull request #2375 from python-discord/allow-passing-channel-objets-whe... (diff) |
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": """ |