[commands] Add UserInputError into the exception hierarchy.
This is for exceptions that are inherently based on user errors and not permission based. e.g. passing incorrect number of arguments, too many arguments, or an invalid argument. CommandNotFound is not classified under this since it isn't inherently a user input error in all cases. Some invalid commands can simply be due to an odd bot prefix. It would also diminish the usefulness of the new parent class if CommandNotFound was included.
This commit is contained in:
parent
0000b2576e
commit
5010e7dc55
@ -28,7 +28,8 @@ from discord.errors import DiscordException
|
|||||||
|
|
||||||
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
|
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
|
||||||
'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
|
'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
|
||||||
'DisabledCommand', 'CommandInvokeError', 'TooManyArguments' ]
|
'DisabledCommand', 'CommandInvokeError', 'TooManyArguments',
|
||||||
|
'UserInputError' ]
|
||||||
|
|
||||||
class CommandError(DiscordException):
|
class CommandError(DiscordException):
|
||||||
"""The base exception type for all command related errors.
|
"""The base exception type for all command related errors.
|
||||||
@ -47,6 +48,14 @@ class CommandError(DiscordException):
|
|||||||
else:
|
else:
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
|
|
||||||
|
class UserInputError(CommandError):
|
||||||
|
"""The base exception type for errors that involve errors
|
||||||
|
regarding user input.
|
||||||
|
|
||||||
|
This inherits from :exc:`CommandError`.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class CommandNotFound(CommandError):
|
class CommandNotFound(CommandError):
|
||||||
"""Exception raised when a command is attempted to be invoked
|
"""Exception raised when a command is attempted to be invoked
|
||||||
but no command under that name is found.
|
but no command under that name is found.
|
||||||
@ -56,13 +65,19 @@ class CommandNotFound(CommandError):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MissingRequiredArgument(CommandError):
|
class MissingRequiredArgument(UserInputError):
|
||||||
"""Exception raised when parsing a command and a parameter
|
"""Exception raised when parsing a command and a parameter
|
||||||
that is required is not encountered.
|
that is required is not encountered.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class BadArgument(CommandError):
|
class TooManyArguments(UserInputError):
|
||||||
|
"""Exception raised when the command was passed too many arguments and its
|
||||||
|
:attr:`Command.ignore_extra` attribute was not set to ``True``.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BadArgument(UserInputError):
|
||||||
"""Exception raised when a parsing or conversion failure is encountered
|
"""Exception raised when a parsing or conversion failure is encountered
|
||||||
on an argument to pass into a command.
|
on an argument to pass into a command.
|
||||||
"""
|
"""
|
||||||
@ -95,8 +110,3 @@ class CommandInvokeError(CommandError):
|
|||||||
self.original = e
|
self.original = e
|
||||||
super().__init__('Command raised an exception: {0.__class__.__name__}: {0}'.format(e))
|
super().__init__('Command raised an exception: {0.__class__.__name__}: {0}'.format(e))
|
||||||
|
|
||||||
class TooManyArguments(CommandError):
|
|
||||||
"""Exception raised when the command was passed too many arguments and its
|
|
||||||
:attr:`Command.ignore_extra` attribute was not set to ``True``.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user