aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinaSakuraba <[email protected]>2017-08-30 17:55:48 -0700
committerRapptz <[email protected]>2017-08-30 23:20:55 -0400
commit8646bddc906c886a9f8bda6839ccfa791f913c2c (patch)
tree13b9e1ab0a34c0bec784a206e0f560383941a68c
parentManually format reason parameter for kick and ban. (diff)
downloaddiscord.py-8646bddc906c886a9f8bda6839ccfa791f913c2c.tar.xz
discord.py-8646bddc906c886a9f8bda6839ccfa791f913c2c.zip
[commands] Add MissingPermissions and BotMissingPermissions
-rw-r--r--discord/ext/commands/errors.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/discord/ext/commands/errors.py b/discord/ext/commands/errors.py
index 555bfd99..c7d87746 100644
--- a/discord/ext/commands/errors.py
+++ b/discord/ext/commands/errors.py
@@ -29,7 +29,8 @@ from discord.errors import DiscordException
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
'DisabledCommand', 'CommandInvokeError', 'TooManyArguments',
- 'UserInputError', 'CommandOnCooldown', 'NotOwner' ]
+ 'UserInputError', 'CommandOnCooldown', 'NotOwner',
+ 'MissingPermissions', 'BotMissingPermissions']
class CommandError(DiscordException):
"""The base exception type for all command related errors.
@@ -136,3 +137,44 @@ class CommandOnCooldown(CommandError):
self.cooldown = cooldown
self.retry_after = retry_after
super().__init__('You are on cooldown. Try again in {:.2f}s'.format(retry_after))
+
+class MissingPermissions(CheckFailure):
+ """Exception raised when the command invoker lacks permissions to run
+ command.
+
+ Attributes
+ -----------
+ missing_perms: list
+ The required permissions that are missing.
+ """
+ def __init__(self, missing_perms, *args):
+ self.missing_perms = missing_perms
+
+ missing = [perm.replace('_', ' ').replace('guild', 'server').title() for perm in missing_perms]
+
+ if len(missing) > 2:
+ fmt = '{}, and {}'.format(", ".join(missing[:-1]), missing[-1])
+ else:
+ fmt = ' and '.join(missing)
+ message = 'You are missing {} permission(s) to run command.'.format(fmt)
+ super().__init__(message, *args)
+
+class BotMissingPermissions(CheckFailure):
+ """Exception raised when the bot lacks permissions to run command.
+
+ Attributes
+ -----------
+ missing_perms: list
+ The required permissions that are missing.
+ """
+ def __init__(self, missing_perms, *args):
+ self.missing_perms = missing_perms
+
+ missing = [perm.replace('_', ' ').replace('guild', 'server').title() for perm in missing_perms]
+
+ if len(missing) > 2:
+ fmt = '{}, and {}'.format(", ".join(missing[:-1]), missing[-1])
+ else:
+ fmt = ' and '.join(missing)
+ message = 'Bot requires {} permission(s) to run command.'.format(fmt)
+ super().__init__(message, *args)