diff --git a/changelog.d/2923.bugfix.rst b/changelog.d/2923.bugfix.rst new file mode 100644 index 000000000..7be210ff8 --- /dev/null +++ b/changelog.d/2923.bugfix.rst @@ -0,0 +1 @@ +Check the recipient balance before transferring and stop transfer if will go above the maximum allowed balance. \ No newline at end of file diff --git a/redbot/core/bank.py b/redbot/core/bank.py index 3b08a5083..ee5bb8948 100644 --- a/redbot/core/bank.py +++ b/redbot/core/bank.py @@ -186,11 +186,7 @@ async def set_balance(member: discord.Member, amount: int) -> int: if amount < 0: raise ValueError("Not allowed to have negative balance.") if amount > MAX_BALANCE: - currency = ( - await get_currency_name() - if await is_global() - else await get_currency_name(member.guild) - ) + currency = await get_currency_name(member.guild) raise errors.BalanceTooHigh( user=member.display_name, max_balance=MAX_BALANCE, currency_name=currency ) @@ -305,6 +301,9 @@ async def transfer_credits(from_: discord.Member, to: discord.Member, amount: in If the amount is invalid or if ``from_`` has insufficient funds. TypeError If the amount is not an `int`. + BalanceTooHigh + If the balance after the transfer would be greater than + ``bank.MAX_BALANCE`` """ if not isinstance(amount, int): @@ -312,6 +311,12 @@ async def transfer_credits(from_: discord.Member, to: discord.Member, amount: in if _invalid_amount(amount): raise ValueError("Invalid transfer amount {} <= 0".format(amount)) + if await get_balance(to) + amount > MAX_BALANCE: + currency = await get_currency_name(to.guild) + raise errors.BalanceTooHigh( + user=to.display_name, max_balance=MAX_BALANCE, currency_name=currency + ) + await withdraw_credits(from_, amount) return await deposit_credits(to, amount)