From 7bc3750c273829727d33da5358e0b2477ef69ed7 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 12 Feb 2017 13:53:28 -0500 Subject: [PATCH] [commands] Add param attribute to MissingRequiredArgument This should allow easier querying on what argument is missing. Fixes #470. --- discord/ext/commands/core.py | 2 +- discord/ext/commands/errors.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 38b5ed6ac..4d65f0583 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -226,7 +226,7 @@ class Command: if param.kind == param.VAR_POSITIONAL: raise RuntimeError() # break the loop if required: - raise MissingRequiredArgument('{0.name} is a required argument that is missing.'.format(param)) + raise MissingRequiredArgument(param) return param.default if consume_rest_is_special: diff --git a/discord/ext/commands/errors.py b/discord/ext/commands/errors.py index 5aa6d1649..07d38a228 100644 --- a/discord/ext/commands/errors.py +++ b/discord/ext/commands/errors.py @@ -68,8 +68,15 @@ class CommandNotFound(CommandError): class MissingRequiredArgument(UserInputError): """Exception raised when parsing a command and a parameter that is required is not encountered. + + Attributes + ----------- + param: str + The argument that is missing. """ - pass + def __init__(self, param): + self.param = param.name + super().__init__('{0.name} is a required argument that is missing.'.format(param)) class TooManyArguments(UserInputError): """Exception raised when the command was passed too many arguments and its