From d2c1b270cebfcca5f081daceeda3dadfa28313e1 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sat, 7 Nov 2020 18:45:51 +0200 Subject: Catch CommandError for help command can_run await --- bot/exts/info/help.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bot/exts/info/help.py b/bot/exts/info/help.py index 5e0651f8a..44bff1f88 100644 --- a/bot/exts/info/help.py +++ b/bot/exts/info/help.py @@ -5,7 +5,7 @@ from contextlib import suppress from typing import List, Union from discord import Colour, Embed -from discord.ext.commands import Bot, Cog, Command, Context, Group, HelpCommand +from discord.ext.commands import Bot, Cog, Command, Context, Group, HelpCommand, DisabledCommand, CommandError from fuzzywuzzy import fuzz, process from fuzzywuzzy.utils import full_process @@ -173,12 +173,16 @@ class CustomHelpCommand(HelpCommand): if aliases: command_details += f"**Can also use:** {aliases}\n\n" - # when command is disabled, show message about it + # when command is disabled, show message about it, + # when other CommandError instance is raised, log warning about it # otherwise check if the user is allowed to run this command - if not command.enabled: + try: + if not await command.can_run(self.context): + command_details += "***You cannot run this command.***\n\n" + except DisabledCommand: command_details += "***This command is disabled.***\n\n" - elif not await command.can_run(self.context): - command_details += "***You cannot run this command.***\n\n" + except CommandError as e: + log.warning(f"An exception raised when trying to check {command.name} command running permission: {e}") command_details += f"*{command.help or 'No details provided.'}*\n" embed.description = command_details -- cgit v1.2.3