# Buggy code
async def set_balance(member: discord.Member, amount: int) -> int:
    """Set an account balance.

    Parameters
    ----------
    member : discord.Member
        The member whose balance to set.
    amount : int
        The amount to set the balance to.

    Returns
    -------
    int
        New account balance.

    Raises
    ------
    ValueError
        If attempting to set the balance to a negative number.

    """
    if amount < 0:
        raise ValueError("Not allowed to have negative balance.")
    if await is_global():
        group = _conf.user(member)
    else:
        group = _conf.member(member)
    await group.balance.set(amount)

    if await group.created_at() == 0:
        time = _encoded_current_time()
        await group.created_at.set(time)

    if await group.name() == "":
        await group.name.set(member.display_name)

    return amount


# Traceback (OverflowError)
ERROR events on_command_error 205: Exception in command 'bank set'
Traceback (most recent call last):
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/discord/ext/commands/core.py", line 61, in wrapped
ret = await coro(*args, **kwargs)
File "/home/zephyrkul/.pyenv/versions/3.7.0/envs/red/lib/python3.7/site-packages/redbot/cogs/economy/economy.py", line 206, in _set
await bank.set_balance(to, creds.sum)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/redbot/core/bank.py", line 181, in set_balance
await group.balance.set(amount)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/redbot/core/config.py", line 152, in set
await self.driver.set(*self.identifiers, value=value)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/redbot/core/drivers/red_mongo.py", line 95, in set
upsert=True,
File "/home/zephyrkul/.pyenv/versions/3.7.0/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/collection.py", line 995, in update_one
session=session),
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/collection.py", line 851, in _update_retryable
_update, session)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1243, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1196, in _retry_with_session
return func(session, sock_info, retryable)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/collection.py", line 847, in _update
retryable_write=retryable_write)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/collection.py", line 817, in _update
retryable_write=retryable_write).copy()
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/pool.py", line 584, in command
self._raise_connection_failure(error)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/pool.py", line 745, in _raise_connection_failure
raise error
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/pool.py", line 579, in command
unacknowledged=unacknowledged)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/network.py", line 114, in command
codec_options, ctx=compression_ctx)
File "/home/zephyrkul/.pyenv/versions/red/lib/python3.7/site-packages/pymongo/message.py", line 679, in _op_msg
flags, command, identifier, docs, check_keys, opts)
OverflowError: MongoDB can only handle up to 8-byte ints

# Fixed code
async def set_balance(member: discord.Member, amount: int) -> int:
    """Set an account balance.

    Parameters
    ----------
    member : discord.Member
        The member whose balance to set.
    amount : int
        The amount to set the balance to.

    Returns
    -------
    int
        New account balance.

    Raises
    ------
    ValueError
        If attempting to set the balance to a negative number.
    BalanceTooHigh
        If attempting to set the balance to a value greater than
        ``bank.MAX_BALANCE``

    """
    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)
        )
        raise errors.BalanceTooHigh(
            user=member.display_name, max_balance=MAX_BALANCE, currency_name=currency
        )
    if await is_global():
        group = _conf.user(member)
    else:
        group = _conf.member(member)
    await group.balance.set(amount)

    if await group.created_at() == 0:
        time = _encoded_current_time()
        await group.created_at.set(time)

    if await group.name() == "":
        await group.name.set(member.display_name)

    return amount