# Buggy code
def to_json(self) -> dict:
    """Transform the object to a dict

    Returns
    -------
    dict
        The case in the form of a dict

    """
    if self.moderator is not None:
        mod = self.moderator.id
    else:
        mod = None
    if isinstance(self.user, int):
        user_id = self.user
    else:
        user_id = self.user.id
    data = {
        "case_number": self.case_number,
        "action_type": self.action_type,
        "guild": self.guild.id,
        "created_at": self.created_at,
        "user": user_id,
        "last_known_username": self.last_known_username,
        "moderator": mod,
        "reason": self.reason,
        "until": self.until,
        "channel": self.channel.id if hasattr(self.channel, "id") else None,
        "amended_by": self.amended_by.id if hasattr(self.amended_by, "id") else None,
        "modified_at": self.modified_at,
        "message": self.message.id if hasattr(self.message, "id") else None,
    }
    return data


# Traceback (AttributeError)
Traceback (most recent call last):
File "/red-v32/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/red-v32/lib/python3.8/site-packages/redbot/cogs/modlog/modlog.py", line 142, in casesfor
rendered_cases = [await case.message_content(embed=embed_requested) for case in cases]
File "/red-v32/lib/python3.8/site-packages/redbot/cogs/modlog/modlog.py", line 142, in <listcomp>
rendered_cases = [await case.message_content(embed=embed_requested) for case in cases]
File "/red-v32/lib/python3.8/site-packages/redbot/core/modlog.py", line 296, in message_content
moderator = escape_spoilers(f"{self.moderator} ({self.moderator.id})")
AttributeError: 'int' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/red-v32/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "/red-v32/lib/python3.8/site-packages/discord/ext/commands/core.py", line 824, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/red-v32/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'int' object has no attribute 'id'

# Fixed code
def to_json(self) -> dict:
    """Transform the object to a dict

    Returns
    -------
    dict
        The case in the form of a dict

    """
    if self.moderator is None or isinstance(self.moderator, int):
        mod = self.moderator
    else:
        mod = self.moderator.id
    if self.amended_by is None or isinstance(self.amended_by, int):
        amended_by = self.amended_by
    else:
        amended_by = self.amended_by.id
    if isinstance(self.user, int):
        user_id = self.user
    else:
        user_id = self.user.id
    data = {
        "case_number": self.case_number,
        "action_type": self.action_type,
        "guild": self.guild.id,
        "created_at": self.created_at,
        "user": user_id,
        "last_known_username": self.last_known_username,
        "moderator": mod,
        "reason": self.reason,
        "until": self.until,
        "channel": self.channel.id if hasattr(self.channel, "id") else None,
        "amended_by": amended_by,
        "modified_at": self.modified_at,
        "message": self.message.id if hasattr(self.message, "id") else None,
    }
    return data