From a4db7a10288a5d6d186828f977a99208fff2caf1 Mon Sep 17 00:00:00 2001 From: Sougata das Date: Fri, 26 Mar 2021 20:30:56 +0530 Subject: [PATCH] Add meaningful error messages for bad arguments in [p]bank set (#4801) * bot will give meaning full message for bad argument * reformated python code and updated warning message! * warning message updated * warning message updated * warning message updated(1) * warning message updated(2) * warning message updated(3) * Address the review Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/cogs/economy/economy.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/redbot/cogs/economy/economy.py b/redbot/cogs/economy/economy.py index 6d56f75e4..39db1c9d2 100644 --- a/redbot/cogs/economy/economy.py +++ b/redbot/cogs/economy/economy.py @@ -101,19 +101,30 @@ def guild_only_check(): class SetParser: def __init__(self, argument): allowed = ("+", "-") - self.sum = int(argument) + try: + self.sum = int(argument) + except ValueError: + raise commands.BadArgument( + _( + "Invalid value, the argument must be an integer," + " optionally preceded with a `+` or `-` sign." + ) + ) if argument and argument[0] in allowed: if self.sum < 0: self.operation = "withdraw" elif self.sum > 0: self.operation = "deposit" else: - raise RuntimeError + raise commands.BadArgument( + _( + "Invalid value, the amount of currency to increase or decrease" + " must be an integer different from zero." + ) + ) self.sum = abs(self.sum) - elif argument.isdigit(): - self.operation = "set" else: - raise RuntimeError + self.operation = "set" @cog_i18n(_)