From bb5e222f29863368a3f4708c9a798efb1f6f19dd Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 23 Jan 2016 03:43:54 -0500 Subject: [commands] Add Bot.help_attrs to customise the help command. The help message now uses the invoked_with attribute of the context to get the name of the command it uses instead of a hardcoded help. --- discord/ext/commands/bot.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'discord/ext/commands/bot.py') diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index d1df7fc2..5530beb4 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -51,7 +51,6 @@ def when_mentioned(bot, msg): to being mentioned, e.g. ``@bot ``.""" return '{0.user.mention} '.format(bot) -@command(pass_context=True, name='help') @asyncio.coroutine def _default_help_command(ctx, *commands : str): """Shows this message.""" @@ -142,6 +141,12 @@ class Bot(GroupMixin, discord.Client): output is PM'd. If ``None``, then the bot will only PM when the help message becomes too long (dictated by more than 1000 characters). Defaults to ``False``. + help_attrs : dict + A dictionary of options to pass in for the construction of the help command. + This allows you to change the command behaviour without actually changing + the implementation of the command. The attributes will be the same as the + ones passed in the :class:`Command` constructor. Note that ``pass_context`` + will always be set to ``True`` regardless of what you pass in. """ def __init__(self, command_prefix, formatter=None, description=None, pm_help=False, **options): super().__init__(**options) @@ -151,6 +156,13 @@ class Bot(GroupMixin, discord.Client): self.extensions = {} self.description = inspect.cleandoc(description) if description else '' self.pm_help = pm_help + + self.help_attrs = options.pop('help_attrs', {}) + self.help_attrs['pass_context'] = True + + if 'name' not in self.help_attrs: + self.help_attrs['name'] = 'help' + if formatter is not None: if not isinstance(formatter, HelpFormatter): raise discord.ClientException('Formatter must be a subclass of HelpFormatter') @@ -158,7 +170,8 @@ class Bot(GroupMixin, discord.Client): else: self.formatter = HelpFormatter() - self.add_command(_default_help_command) + # pay no mind to this ugliness. + self.command(**self.help_attrs)(_default_help_command) # internal helpers -- cgit v1.2.3