mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-21 00:07:51 +00:00
[commands] Add MissingPermissions and BotMissingPermissions
This commit is contained in:
parent
63bca6604b
commit
8646bddc90
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user