[commands] Add Command.ignore_extra attribute to ignore extra arguments
This allows you to strictly require a number of arguments. The default behaviour in this case is still `True`, since it would be a breaking change otherwise and is a sane default. However if someone would want to set this to `False`, they would receive an exception of type `TooManyArguments` if too many arguments are passed to a command. Hopefully this removes the uses of `ctx.message.content == 'stuff'` inside commands.
This commit is contained in:
		@@ -28,7 +28,7 @@ from discord.errors import DiscordException
 | 
			
		||||
 | 
			
		||||
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
 | 
			
		||||
           'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
 | 
			
		||||
           'DisabledCommand', 'CommandInvokeError' ]
 | 
			
		||||
           'DisabledCommand', 'CommandInvokeError', 'TooManyArguments' ]
 | 
			
		||||
 | 
			
		||||
class CommandError(DiscordException):
 | 
			
		||||
    """The base exception type for all command related errors.
 | 
			
		||||
@@ -94,3 +94,9 @@ class CommandInvokeError(CommandError):
 | 
			
		||||
    def __init__(self, e):
 | 
			
		||||
        self.original = 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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user