From 8c0c410d0e6ef0294f86ca834921b8996ba7c954 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 24 Mar 2019 14:27:37 -0400 Subject: [PATCH] [commands] Add HelpCommand.invoked_with This fixes an issue where the context invoked_with does not match the actual invoked with behaviour (e.g. using Context.send_help). --- discord/ext/commands/help.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index 999ef7b0e..f507d945b 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -314,6 +314,26 @@ class HelpCommand: # odd one. return self.context.prefix.replace(user.mention, '@' + user.display_name) + @property + def invoked_with(self): + """Similar to :attr:`Context.invoked_with` except properly handles + the case where :meth:`Context.send_help` is used. + + If the help command was used regularly then this returns + the :attr:`Context.invoked_with` attribute. Otherwise, if + it the help command was called using :meth:`Context.send_help` + then it returns the internal command name of the help command. + + Returns + --------- + :class:`str` + The command name that triggered this invocation. + """ + command_name = self._command_impl.name + if self.context is None or self.context.command.qualified_name != command_name: + return command_name + return self.context.invoked_with + def get_command_signature(self, command): """Retrieves the signature portion of the help page. @@ -826,7 +846,7 @@ class DefaultHelpCommand(HelpCommand): def get_ending_note(self): """Returns help command's ending note. This is mainly useful to override for i18n purposes.""" - command_name = self.context.invoked_with + command_name = self.invoked_with return "Type {0}{1} command for more info on a command.\n" \ "You can also type {0}{1} category for more info on a category.".format(self.clean_prefix, command_name) @@ -1031,7 +1051,7 @@ class MinimalHelpCommand(HelpCommand): You can also use `{prefix}{command_name} ` for more info on a category. """ - command_name = self.context.invoked_with + command_name = self.invoked_with return "Use `{0}{1} ` for more info on a command.\n" \ "You can also use `{0}{1} ` for more info on a category.".format(self.clean_prefix, command_name)