diff options
| author | Rapptz <[email protected]> | 2017-08-13 20:52:12 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-08-15 06:12:09 -0400 |
| commit | fce2ef553474007dc413fd599454274fce7f6416 (patch) | |
| tree | ee85945031b3d7a74d06d82c238364e160d712d7 | |
| parent | Fix extraneous parentheses in Client.emojis render in migrating docs. (diff) | |
| download | discord.py-fce2ef553474007dc413fd599454274fce7f6416.tar.xz discord.py-fce2ef553474007dc413fd599454274fce7f6416.zip | |
[commands] Raise when an invalid prefix is given.
Fixes #712
| -rw-r--r-- | discord/ext/commands/bot.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 55c97301..5b872f88 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -785,20 +785,33 @@ class BotBase(GroupMixin): message: :class:`discord.Message` The message context to get the prefix of. + Raises + -------- + :exc:`.ClientException` + The prefix was invalid. This could be if the prefix + function returned None, the prefix list returned no + elements that aren't None, or the prefix string is + empty. + Returns -------- Union[List[str], str] A list of prefixes or a single prefix that the bot is listening for. """ - prefix = self.command_prefix + prefix = ret = self.command_prefix if callable(prefix): ret = prefix(self, message) if asyncio.iscoroutine(ret): ret = yield from ret - return ret - else: - return prefix + + if isinstance(ret, (list, tuple)): + ret = [p for p in ret if p] + + if not ret: + raise ClientException('invalid prefix (could be an empty string, empty list, or None)') + + return ret @asyncio.coroutine def get_context(self, message, *, cls=Context): @@ -840,7 +853,7 @@ class BotBase(GroupMixin): prefix = yield from self.get_prefix(message) invoked_prefix = prefix - if not isinstance(prefix, (tuple, list)): + if isinstance(prefix, str): if not view.skip_string(prefix): return ctx else: |