mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
[commands] Allow registration of multiple command prefixes.
This commit is contained in:
parent
a2b97ae2db
commit
542ddc4938
@ -43,7 +43,7 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
This class also subclasses :class:`GroupMixin` to provide the functionality
|
This class also subclasses :class:`GroupMixin` to provide the functionality
|
||||||
to manage commands.
|
to manage commands.
|
||||||
|
|
||||||
Parameters
|
Attributes
|
||||||
-----------
|
-----------
|
||||||
command_prefix
|
command_prefix
|
||||||
The command prefix is what the message content must contain initially
|
The command prefix is what the message content must contain initially
|
||||||
@ -51,6 +51,11 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
indicate what the prefix should be, or a callable that takes in a
|
indicate what the prefix should be, or a callable that takes in a
|
||||||
:class:`discord.Message` as its first parameter and returns the prefix.
|
:class:`discord.Message` as its first parameter and returns the prefix.
|
||||||
This is to facilitate "dynamic" command prefixes.
|
This is to facilitate "dynamic" command prefixes.
|
||||||
|
|
||||||
|
The command prefix could also be a list or a tuple indicating that
|
||||||
|
multiple checks for the prefix should be used and the first one to
|
||||||
|
match will be the invocation prefix. You can get this prefix via
|
||||||
|
:attr:`Context.prefix`.
|
||||||
"""
|
"""
|
||||||
def __init__(self, command_prefix, **options):
|
def __init__(self, command_prefix, **options):
|
||||||
super().__init__(**options)
|
super().__init__(**options)
|
||||||
@ -199,8 +204,16 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
return
|
return
|
||||||
|
|
||||||
prefix = self._get_prefix(message)
|
prefix = self._get_prefix(message)
|
||||||
if not view.skip_string(prefix):
|
invoked_prefix = prefix
|
||||||
return
|
|
||||||
|
if not isinstance(prefix, (tuple, list)):
|
||||||
|
if not view.skip_string(prefix):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
invoked_prefix = discord.utils.find(view.skip_string, prefix)
|
||||||
|
if invoked_prefix is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
invoker = view.get_word()
|
invoker = view.get_word()
|
||||||
tmp = {
|
tmp = {
|
||||||
@ -208,6 +221,7 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
'invoked_with': invoker,
|
'invoked_with': invoker,
|
||||||
'message': message,
|
'message': message,
|
||||||
'view': view,
|
'view': view,
|
||||||
|
'prefix': invoked_prefix
|
||||||
}
|
}
|
||||||
ctx = Context(**tmp)
|
ctx = Context(**tmp)
|
||||||
del tmp
|
del tmp
|
||||||
|
@ -46,6 +46,8 @@ class Context:
|
|||||||
A dictionary of transformed arguments that were passed into the command.
|
A dictionary of transformed arguments that were passed into the command.
|
||||||
Similar to :attr:`args`\, if this is accessed in the
|
Similar to :attr:`args`\, if this is accessed in the
|
||||||
:func:`on_command_error` event then this dict could be incomplete.
|
:func:`on_command_error` event then this dict could be incomplete.
|
||||||
|
prefix : str
|
||||||
|
The prefix that was used to invoke the command.
|
||||||
command
|
command
|
||||||
The command (i.e. :class:`Command` or its superclasses) that is being
|
The command (i.e. :class:`Command` or its superclasses) that is being
|
||||||
invoked currently.
|
invoked currently.
|
||||||
@ -63,13 +65,15 @@ class Context:
|
|||||||
subcommand then this is set to `None`.
|
subcommand then this is set to `None`.
|
||||||
"""
|
"""
|
||||||
__slots__ = ['message', 'bot', 'args', 'kwargs', 'command', 'view',
|
__slots__ = ['message', 'bot', 'args', 'kwargs', 'command', 'view',
|
||||||
'invoked_with', 'invoked_subcommand', 'subcommand_passed']
|
'invoked_with', 'invoked_subcommand', 'subcommand_passed',
|
||||||
|
'prefix' ]
|
||||||
|
|
||||||
def __init__(self, **attrs):
|
def __init__(self, **attrs):
|
||||||
self.message = attrs.pop('message', None)
|
self.message = attrs.pop('message', None)
|
||||||
self.bot = attrs.pop('bot', None)
|
self.bot = attrs.pop('bot', None)
|
||||||
self.args = attrs.pop('args', [])
|
self.args = attrs.pop('args', [])
|
||||||
self.kwargs = attrs.pop('kwargs', {})
|
self.kwargs = attrs.pop('kwargs', {})
|
||||||
|
self.prefix = attrs.pop('prefix')
|
||||||
self.command = attrs.pop('command', None)
|
self.command = attrs.pop('command', None)
|
||||||
self.view = attrs.pop('view', None)
|
self.view = attrs.pop('view', None)
|
||||||
self.invoked_with = attrs.pop('invoked_with', None)
|
self.invoked_with = attrs.pop('invoked_with', None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user