# Buggy code
def parse_presence_update(self, data):
    guild_id = utils._get_as_snowflake(data, "guild_id")
    guild = self._get_guild(guild_id)
    if guild is None:
        log.debug(
            "PRESENCE_UPDATE referencing an unknown guild ID: %s. Discarding.", guild_id
        )
        return

    user = data["user"]
    member_id = int(user["id"])
    member = guild.get_member(member_id)
    flags = self._member_cache_flags
    if member is None:
        if "username" not in user:
            # sometimes we receive 'incomplete' member data post-removal.
            # skip these useless cases.
            return

        member, old_member = Member._from_presence_update(
            guild=guild, data=data, state=self
        )
        if flags.online or (flags._online_only and member.raw_status != "offline"):
            guild._add_member(member)
    else:
        old_member = Member._copy(member)
        user_update = member._presence_update(data=data, user=user)
        if user_update:
            self.dispatch("user_update", user_update[0], user_update[1])

        if (
            member.id != self.self_id
            and flags._online_only
            and member.raw_status == "offline"
        ):
            guild._remove_member(member)

    self.dispatch("member_update", old_member, member)


# Traceback (AttributeError)
Ignoring exception in command guild:
Traceback (most recent call last):
File "\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\\Desktop\Coding\Python\Lost... Bot\Cogs\staff.py", line 36, in guild
temp = await self.bot.fetch_template(code)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 1144, in fetch_template
return Template(data=data, state=self._connection)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\template.py", line 120, in __init__
self.source_guild = Guild(data=source_serialised, state=state)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\guild.py", line 190, in __init__
self._from_data(data)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\guild.py", line 308, in _from_data
cache_online_members = self._state._member_cache_flags.online
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\template.py", line 75, in __getattr__
raise AttributeError('PartialTemplateState does not support {0!r}.'.format(attr))
AttributeError: PartialTemplateState does not support '_member_cache_flags'.

# Fixed code
def parse_presence_update(self, data):
    guild_id = utils._get_as_snowflake(data, "guild_id")
    guild = self._get_guild(guild_id)
    if guild is None:
        log.debug(
            "PRESENCE_UPDATE referencing an unknown guild ID: %s. Discarding.", guild_id
        )
        return

    user = data["user"]
    member_id = int(user["id"])
    member = guild.get_member(member_id)
    flags = self.member_cache_flags
    if member is None:
        if "username" not in user:
            # sometimes we receive 'incomplete' member data post-removal.
            # skip these useless cases.
            return

        member, old_member = Member._from_presence_update(
            guild=guild, data=data, state=self
        )
        if flags.online or (flags._online_only and member.raw_status != "offline"):
            guild._add_member(member)
    else:
        old_member = Member._copy(member)
        user_update = member._presence_update(data=data, user=user)
        if user_update:
            self.dispatch("user_update", user_update[0], user_update[1])

        if (
            member.id != self.self_id
            and flags._online_only
            and member.raw_status == "offline"
        ):
            guild._remove_member(member)

    self.dispatch("member_update", old_member, member)