Browse Source

[commands] Add support for self-bots.

pull/220/merge
Rapptz 9 years ago
parent
commit
3c8fcd3584
  1. 10
      discord/ext/commands/bot.py

10
discord/ext/commands/bot.py

@ -152,6 +152,10 @@ class Bot(GroupMixin, discord.Client):
:attr:`Context.prefix`. :attr:`Context.prefix`.
description : str description : str
The content prefixed into the default help message. The content prefixed into the default help message.
self_bot : bool
If ``True``, the bot will only listen to commands invoked by itself rather
than ignoring itself. If ``False`` (the default) then the bot will ignore
itself. This cannot be changed once initialised.
formatter : :class:`HelpFormatter` formatter : :class:`HelpFormatter`
The formatter used to format the help message. By default, it uses a The formatter used to format the help message. By default, it uses a
the :class:`HelpFormatter`. Check it for more info on how to override it. the :class:`HelpFormatter`. Check it for more info on how to override it.
@ -192,6 +196,8 @@ class Bot(GroupMixin, discord.Client):
self.command_not_found = options.pop('command_not_found', 'No command called "{}" found.') self.command_not_found = options.pop('command_not_found', 'No command called "{}" found.')
self.command_has_no_subcommands = options.pop('command_has_no_subcommands', 'Command {0.name} has no subcommands.') self.command_has_no_subcommands = options.pop('command_has_no_subcommands', 'Command {0.name} has no subcommands.')
self._skip_check = discord.User.__ne__ if options.pop('self_bot', False) else discord.User.__eq__
self.help_attrs = options.pop('help_attrs', {}) self.help_attrs = options.pop('help_attrs', {})
self.help_attrs['pass_context'] = True self.help_attrs['pass_context'] = True
@ -457,7 +463,7 @@ class Bot(GroupMixin, discord.Client):
return self.cogs.get(name) return self.cogs.get(name)
def remove_cog(self, name): def remove_cog(self, name):
"""Removes a cog the bot. """Removes a cog from the bot.
All registered commands and event listeners that the All registered commands and event listeners that the
cog has registered will be removed as well. cog has registered will be removed as well.
@ -578,7 +584,7 @@ class Bot(GroupMixin, discord.Client):
_internal_author = message.author _internal_author = message.author
view = StringView(message.content) view = StringView(message.content)
if message.author == self.user: if self._skip_check(message.author, self.user):
return return
prefix = self._get_prefix(message) prefix = self._get_prefix(message)

Loading…
Cancel
Save