# Buggy code
async def slot_machine(author, channel, bid):
    default_reel = deque(cast(Iterable, SMReel))
    reels = []
    for i in range(3):
        default_reel.rotate(random.randint(-999, 999))  # weeeeee
        new_reel = deque(default_reel, maxlen=3)  # we need only 3 symbols
        reels.append(new_reel)  # for each reel
    rows = (
        (reels[0][0], reels[1][0], reels[2][0]),
        (reels[0][1], reels[1][1], reels[2][1]),
        (reels[0][2], reels[1][2], reels[2][2]),
    )

    slot = "~~\n~~"  # Mobile friendly
    for i, row in enumerate(rows):  # Let's build the slot to show
        sign = "  "
        if i == 1:
            sign = ">"
        slot += "{}{} {} {}\n".format(sign, *[c.value for c in row])

    payout = PAYOUTS.get(rows[1])
    if not payout:
        # Checks for two-consecutive-symbols special rewards
        payout = PAYOUTS.get(
            (rows[1][0], rows[1][1]), PAYOUTS.get((rows[1][1], rows[1][2]))
        )
    if not payout:
        # Still nothing. Let's check for 3 generic same symbols
        # or 2 consecutive symbols
        has_three = rows[1][0] == rows[1][1] == rows[1][2]
        has_two = (rows[1][0] == rows[1][1]) or (rows[1][1] == rows[1][2])
        if has_three:
            payout = PAYOUTS["3 symbols"]
        elif has_two:
            payout = PAYOUTS["2 symbols"]

    if payout:
        then = await bank.get_balance(author)
        pay = payout["payout"](bid)
        now = then - bid + pay
        await bank.set_balance(author, now)
        phrase = T_(payout["phrase"])
    else:
        then = await bank.get_balance(author)
        await bank.withdraw_credits(author, bid)
        now = then - bid
        phrase = _("Nothing!")
    await channel.send(
        (
            "{slot}\n{author.mention} {phrase}\n\n"
            + _("Your bid: {amount}")
            + "\n{old_balance} → {new_balance}!"
        ).format(
            slot=slot,
            author=author,
            phrase=phrase,
            amount=bid,
            old_balance=then,
            new_balance=now,
        )
    )


# 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 slot_machine(author, channel, bid):
    default_reel = deque(cast(Iterable, SMReel))
    reels = []
    for i in range(3):
        default_reel.rotate(random.randint(-999, 999))  # weeeeee
        new_reel = deque(default_reel, maxlen=3)  # we need only 3 symbols
        reels.append(new_reel)  # for each reel
    rows = (
        (reels[0][0], reels[1][0], reels[2][0]),
        (reels[0][1], reels[1][1], reels[2][1]),
        (reels[0][2], reels[1][2], reels[2][2]),
    )

    slot = "~~\n~~"  # Mobile friendly
    for i, row in enumerate(rows):  # Let's build the slot to show
        sign = "  "
        if i == 1:
            sign = ">"
        slot += "{}{} {} {}\n".format(sign, *[c.value for c in row])

    payout = PAYOUTS.get(rows[1])
    if not payout:
        # Checks for two-consecutive-symbols special rewards
        payout = PAYOUTS.get(
            (rows[1][0], rows[1][1]), PAYOUTS.get((rows[1][1], rows[1][2]))
        )
    if not payout:
        # Still nothing. Let's check for 3 generic same symbols
        # or 2 consecutive symbols
        has_three = rows[1][0] == rows[1][1] == rows[1][2]
        has_two = (rows[1][0] == rows[1][1]) or (rows[1][1] == rows[1][2])
        if has_three:
            payout = PAYOUTS["3 symbols"]
        elif has_two:
            payout = PAYOUTS["2 symbols"]

    if payout:
        then = await bank.get_balance(author)
        pay = payout["payout"](bid)
        now = then - bid + pay
        try:
            await bank.set_balance(author, now)
        except errors.BalanceTooHigh as exc:
            await bank.set_balance(author, exc.max_balance)
            await channel.send(
                _(
                    "You've reached the maximum amount of {currency}! "
                    "Please spend some more \N{GRIMACING FACE}\n{old_balance} -> {new_balance}!"
                ).format(
                    currency=await bank.get_currency_name(
                        getattr(channel, "guild", None)
                    ),
                    old_balance=then,
                    new_balance=exc.max_balance,
                )
            )
            return
        phrase = T_(payout["phrase"])
    else:
        then = await bank.get_balance(author)
        await bank.withdraw_credits(author, bid)
        now = then - bid
        phrase = _("Nothing!")
    await channel.send(
        (
            "{slot}\n{author.mention} {phrase}\n\n"
            + _("Your bid: {amount}")
            + "\n{old_balance} → {new_balance}!"
        ).format(
            slot=slot,
            author=author,
            phrase=phrase,
            amount=bid,
            old_balance=then,
            new_balance=now,
        )
    )