aboutsummaryrefslogtreecommitdiff
path: root/discord/ext/commands/bot.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-07 16:20:33 -0500
committerRapptz <[email protected]>2016-01-07 16:20:33 -0500
commit542ddc49386dbb103ce8172831c37189acf93017 (patch)
treecd92fac2c9c95cd1b2e0f443c0c4c9b676ab7ba7 /discord/ext/commands/bot.py
parentFix handling of embed-only MESSAGE_UPDATE. (diff)
downloaddiscord.py-542ddc49386dbb103ce8172831c37189acf93017.tar.xz
discord.py-542ddc49386dbb103ce8172831c37189acf93017.zip
[commands] Allow registration of multiple command prefixes.
Diffstat (limited to 'discord/ext/commands/bot.py')
-rw-r--r--discord/ext/commands/bot.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index c602a204..9d5a09de 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -43,7 +43,7 @@ class Bot(GroupMixin, discord.Client):
This class also subclasses :class:`GroupMixin` to provide the functionality
to manage commands.
- Parameters
+ Attributes
-----------
command_prefix
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
:class:`discord.Message` as its first parameter and returns the prefix.
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):
super().__init__(**options)
@@ -199,8 +204,16 @@ class Bot(GroupMixin, discord.Client):
return
prefix = self._get_prefix(message)
- if not view.skip_string(prefix):
- return
+ invoked_prefix = prefix
+
+ 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()
tmp = {
@@ -208,6 +221,7 @@ class Bot(GroupMixin, discord.Client):
'invoked_with': invoker,
'message': message,
'view': view,
+ 'prefix': invoked_prefix
}
ctx = Context(**tmp)
del tmp