# Buggy code
async def payday(self, ctx: commands.Context):
    """Get some free currency."""
    author = ctx.author
    guild = ctx.guild

    cur_time = calendar.timegm(ctx.message.created_at.utctimetuple())
    credits_name = await bank.get_currency_name(ctx.guild)
    if await bank.is_global():  # Role payouts will not be used
        next_payday = await self.config.user(author).next_payday()
        if cur_time >= next_payday:
            await bank.deposit_credits(author, await self.config.PAYDAY_CREDITS())
            next_payday = cur_time + await self.config.PAYDAY_TIME()
            await self.config.user(author).next_payday.set(next_payday)

            pos = await bank.get_leaderboard_position(author)
            await ctx.send(
                _(
                    "{author.mention} Here, take some {currency}. "
                    "Enjoy! (+{amount} {currency}!)\n\n"
                    "You currently have {new_balance} {currency}.\n\n"
                    "You are currently #{pos} on the global leaderboard!"
                ).format(
                    author=author,
                    currency=credits_name,
                    amount=await self.config.PAYDAY_CREDITS(),
                    new_balance=await bank.get_balance(author),
                    pos=pos,
                )
            )

        else:
            dtime = self.display_time(next_payday - cur_time)
            await ctx.send(
                _(
                    "{author.mention} Too soon. For your next payday you have to wait {time}."
                ).format(author=author, time=dtime)
            )
    else:
        next_payday = await self.config.member(author).next_payday()
        if cur_time >= next_payday:
            credit_amount = await self.config.guild(guild).PAYDAY_CREDITS()
            for role in author.roles:
                role_credits = await self.config.role(
                    role
                ).PAYDAY_CREDITS()  # Nice variable name
                if role_credits > credit_amount:
                    credit_amount = role_credits
            await bank.deposit_credits(author, credit_amount)
            next_payday = cur_time + await self.config.guild(guild).PAYDAY_TIME()
            await self.config.member(author).next_payday.set(next_payday)
            pos = await bank.get_leaderboard_position(author)
            await ctx.send(
                _(
                    "{author.mention} Here, take some {currency}. "
                    "Enjoy! (+{amount} {new_balance}!)\n\n"
                    "You currently have {new_balance} {currency}.\n\n"
                    "You are currently #{pos} on the global leaderboard!"
                ).format(
                    author=author,
                    currency=credits_name,
                    amount=credit_amount,
                    new_balance=await bank.get_balance(author),
                    pos=pos,
                )
            )
        else:
            dtime = self.display_time(next_payday - cur_time)
            await ctx.send(
                _(
                    "{author.mention} Too soon. For your next payday you have to wait {time}."
                ).format(author=author, time=dtime)
            )


# 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 payday(self, ctx: commands.Context):
    """Get some free currency."""
    author = ctx.author
    guild = ctx.guild

    cur_time = calendar.timegm(ctx.message.created_at.utctimetuple())
    credits_name = await bank.get_currency_name(ctx.guild)
    if await bank.is_global():  # Role payouts will not be used
        next_payday = await self.config.user(author).next_payday()
        if cur_time >= next_payday:
            try:
                await bank.deposit_credits(author, await self.config.PAYDAY_CREDITS())
            except errors.BalanceTooHigh as exc:
                await bank.set_balance(author, exc.max_balance)
                await ctx.send(
                    _(
                        "You've reached the maximum amount of {currency}! (**{balance:,}**) "
                        "Please spend some more \N{GRIMACING FACE}\n\n"
                        "You currently have {new_balance} {currency}."
                    ).format(currency=credits_name, new_balance=exc.max_balance)
                )
                return
            next_payday = cur_time + await self.config.PAYDAY_TIME()
            await self.config.user(author).next_payday.set(next_payday)

            pos = await bank.get_leaderboard_position(author)
            await ctx.send(
                _(
                    "{author.mention} Here, take some {currency}. "
                    "Enjoy! (+{amount} {currency}!)\n\n"
                    "You currently have {new_balance} {currency}.\n\n"
                    "You are currently #{pos} on the global leaderboard!"
                ).format(
                    author=author,
                    currency=credits_name,
                    amount=await self.config.PAYDAY_CREDITS(),
                    new_balance=await bank.get_balance(author),
                    pos=pos,
                )
            )

        else:
            dtime = self.display_time(next_payday - cur_time)
            await ctx.send(
                _(
                    "{author.mention} Too soon. For your next payday you have to wait {time}."
                ).format(author=author, time=dtime)
            )
    else:
        next_payday = await self.config.member(author).next_payday()
        if cur_time >= next_payday:
            credit_amount = await self.config.guild(guild).PAYDAY_CREDITS()
            for role in author.roles:
                role_credits = await self.config.role(
                    role
                ).PAYDAY_CREDITS()  # Nice variable name
                if role_credits > credit_amount:
                    credit_amount = role_credits
            try:
                await bank.deposit_credits(author, credit_amount)
            except errors.BalanceTooHigh as exc:
                await bank.set_balance(author, exc.max_balance)
                await ctx.send(
                    _(
                        "You've reached the maximum amount of {currency}! "
                        "Please spend some more \N{GRIMACING FACE}\n\n"
                        "You currently have {new_balance} {currency}."
                    ).format(currency=credits_name, new_balance=exc.max_balance)
                )
                return
            next_payday = cur_time + await self.config.guild(guild).PAYDAY_TIME()
            await self.config.member(author).next_payday.set(next_payday)
            pos = await bank.get_leaderboard_position(author)
            await ctx.send(
                _(
                    "{author.mention} Here, take some {currency}. "
                    "Enjoy! (+{amount} {currency}!)\n\n"
                    "You currently have {new_balance} {currency}.\n\n"
                    "You are currently #{pos} on the global leaderboard!"
                ).format(
                    author=author,
                    currency=credits_name,
                    amount=credit_amount,
                    new_balance=await bank.get_balance(author),
                    pos=pos,
                )
            )
        else:
            dtime = self.display_time(next_payday - cur_time)
            await ctx.send(
                _(
                    "{author.mention} Too soon. For your next payday you have to wait {time}."
                ).format(author=author, time=dtime)
            )