Skip to content

Team

attrs class TeamMember (DiscordObject)

Attr attributes:

Name Type Description
id int

Discord unique snowflake ID

membership_state TeamMembershipState

Rhe user's membership state on the team

team_id Snowflake_Type

Rhe id of the parent team of which they are a member

user User

Rhe avatar, discriminator, id, and username of the user

Source code in naff/models/discord/team.py
@define()
class TeamMember(DiscordObject):
    membership_state: TeamMembershipState = field(converter=TeamMembershipState)
    """Rhe user's membership state on the team"""
    # permissions: List[str] = field(default=["*"])  # disabled until discord adds more team roles
    team_id: "Snowflake_Type" = field(repr=True)
    """Rhe id of the parent team of which they are a member"""
    user: "User" = field()  # TODO: cache partial user (avatar, discrim, id, username)
    """Rhe avatar, discriminator, id, and username of the user"""

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data["user"] = client.cache.place_user_data(data["user"])
        data["id"] = data["user"].id
        return data

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/team.py
def update_from_dict(self, data) -> T:
    data = self._process_dict(data, self._client)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

inherited property readonly created_at: models.Timestamp

Returns a timestamp representing the date-time this discord object was created.

:Returns:

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/team.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)

attrs class Team (DiscordObject)

Attr attributes:

Name Type Description
id int

Discord unique snowflake ID

icon Optional[naff.models.discord.asset.Asset]

A hash of the image of the team's icon

members List[naff.models.discord.team.TeamMember]

The members of the team

name str

The name of the team

owner_user_id Snowflake_Type

The user id of the current team owner

Source code in naff/models/discord/team.py
@define()
class Team(DiscordObject):
    icon: Optional[Asset] = field(default=None)
    """A hash of the image of the team's icon"""
    members: List[TeamMember] = field(factory=list)
    """The members of the team"""
    name: str = field(repr=True)
    """The name of the team"""
    owner_user_id: "Snowflake_Type" = field(converter=to_snowflake)
    """The user id of the current team owner"""

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data["members"] = TeamMember.from_list(data["members"], client)
        if data["icon"]:
            data["icon"] = Asset.from_path_hash(client, f"team-icons/{data['id']}/{{}}", data["icon"])
        return data

    @property
    def owner(self) -> "User":
        """The owner of the team"""
        return self._client.cache.get_user(self.owner_user_id)

    def is_in_team(self, user: Union["SnowflakeObject", "Snowflake_Type"]) -> bool:
        """
        Returns True if the passed user or ID is a member within the team.

        Args:
            user: The user or user ID to check

        Returns:
            Boolean indicating whether the user is in the team
        """
        return to_snowflake(user) in [m.id for m in self.members]

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/team.py
def update_from_dict(self, data) -> T:
    data = self._process_dict(data, self._client)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

property readonly owner: User

The owner of the team

method is_in_team(self, user)

Returns True if the passed user or ID is a member within the team.

Parameters:

Name Type Description Default
user Union[SnowflakeObject, Snowflake_Type]

The user or user ID to check

required

Returns:

Type Description
bool

Boolean indicating whether the user is in the team

Source code in naff/models/discord/team.py
def is_in_team(self, user: Union["SnowflakeObject", "Snowflake_Type"]) -> bool:
    """
    Returns True if the passed user or ID is a member within the team.

    Args:
        user: The user or user ID to check

    Returns:
        Boolean indicating whether the user is in the team
    """
    return to_snowflake(user) in [m.id for m in self.members]

inherited property readonly created_at: models.Timestamp

Returns a timestamp representing the date-time this discord object was created.

:Returns:

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/team.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)