aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-01-19 09:08:31 -0800
committerGravatar GitHub <[email protected]>2021-01-19 09:08:31 -0800
commit0f215c190d765acff83eefb2e9d5ab6b38023c62 (patch)
tree9ba5381369d44499324f3acba81c0f7291521725
parentMerge pull request #1368 from python-discord/mbaruh/filters (diff)
parentMerge branch 'master' into help-disabled-command (diff)
Merge pull request #1188 from ks129/help-disabled-command
Help: Add handling of disabled commands to avoid DisabledCommand error
-rw-r--r--bot/exts/info/help.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/bot/exts/info/help.py b/bot/exts/info/help.py
index 461ff82fd..3a05b2c8a 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, CommandError, Context, DisabledCommand, Group, HelpCommand
from fuzzywuzzy import fuzz, process
from fuzzywuzzy.utils import full_process
@@ -20,6 +20,8 @@ log = logging.getLogger(__name__)
COMMANDS_PER_PAGE = 8
PREFIX = constants.Bot.prefix
+NOT_ALLOWED_TO_RUN_MESSAGE = "***You cannot run this command.***\n\n"
+
Category = namedtuple("Category", ["name", "description", "cogs"])
@@ -173,9 +175,16 @@ class CustomHelpCommand(HelpCommand):
if aliases:
command_details += f"**Can also use:** {aliases}\n\n"
- # check if the user is allowed to run this command
- if not await command.can_run(self.context):
- command_details += "***You cannot run this command.***\n\n"
+ # when command is disabled, show message about it,
+ # when other CommandError or user is not allowed to run command,
+ # add this to help message.
+ try:
+ if not await command.can_run(self.context):
+ command_details += NOT_ALLOWED_TO_RUN_MESSAGE
+ except DisabledCommand:
+ command_details += "***This command is disabled.***\n\n"
+ except CommandError:
+ command_details += NOT_ALLOWED_TO_RUN_MESSAGE
command_details += f"*{command.help or 'No details provided.'}*\n"
embed.description = command_details