mirror of
				https://github.com/Rapptz/discord.py.git
				synced 2025-10-25 10:32:59 +00:00 
			
		
		
		
	[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).
This commit is contained in:
		| @@ -314,6 +314,26 @@ class HelpCommand: | |||||||
|         # odd one. |         # odd one. | ||||||
|         return self.context.prefix.replace(user.mention, '@' + user.display_name) |         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): |     def get_command_signature(self, command): | ||||||
|         """Retrieves the signature portion of the help page. |         """Retrieves the signature portion of the help page. | ||||||
|  |  | ||||||
| @@ -826,7 +846,7 @@ class DefaultHelpCommand(HelpCommand): | |||||||
|  |  | ||||||
|     def get_ending_note(self): |     def get_ending_note(self): | ||||||
|         """Returns help command's ending note. This is mainly useful to override for i18n purposes.""" |         """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" \ |         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) |                "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} <category>` for more info on a category. |             You can also use `{prefix}{command_name} <category>` for more info on a category. | ||||||
|  |  | ||||||
|         """ |         """ | ||||||
|         command_name = self.context.invoked_with |         command_name = self.invoked_with | ||||||
|         return "Use `{0}{1} <command>` for more info on a command.\n" \ |         return "Use `{0}{1} <command>` for more info on a command.\n" \ | ||||||
|                "You can also use `{0}{1} <category>` for more info on a category.".format(self.clean_prefix, command_name) |                "You can also use `{0}{1} <category>` for more info on a category.".format(self.clean_prefix, command_name) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user