diff --git a/discord/client.py b/discord/client.py index 12689c835..a2eda7d8e 100644 --- a/discord/client.py +++ b/discord/client.py @@ -54,7 +54,7 @@ from .utils import MISSING from .object import Object from .backoff import ExponentialBackoff from .webhook import Webhook -from .appinfo import Application +from .appinfo import Application, PartialApplication from .stage_instance import StageInstance from .threads import Thread from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory @@ -2007,10 +2007,10 @@ class Client: ... @overload - async def send_friend_request(self, username: str, discriminator: Union[int, str]) -> Relationship: + async def send_friend_request(self, username: str, discriminator: str) -> Relationship: ... - async def send_friend_request(self, *args: Union[BaseUser, int, str]) -> Relationship: + async def send_friend_request(self, *args: Union[BaseUser, str]) -> Relationship: """|coro| Sends a friend request to another user. @@ -2052,7 +2052,7 @@ class Client: The new relationship. """ username: str - discrim: Union[str, int] + discrim: str if len(args) == 1: user = args[0] if isinstance(user, BaseUser): @@ -2067,6 +2067,122 @@ class Client: data = await state.http.send_friend_request(username, discrim) return Relationship(state=state, data=data) + async def applications(self, *, with_team_applications: bool = True) -> List[Application]: + """|coro| + + Retrieves all applications owned by you. + + .. versionadded:: 2.0 + + Parameters + ----------- + with_team_applications: :class:`bool` + Whether to include applications owned by teams you're a part of. + Defaults to ``True``. + + Raises + ------- + :exc:`.HTTPException` + Retrieving the applications failed. + + Returns + ------- + List[:class:`.Application`] + The applications you own. + """ + state = self._connection + data = await state.http.get_my_applications(with_team_applications=with_team_applications) + return [Application(state=state, data=d) for d in data] + + async def fetch_application(self, app_id: int, /) -> Application: + """|coro| + + Retrieves the application with the given ID. + + The application must be owned by you. + + .. versionadded:: 2.0 + + Parameters + ----------- + id: :class:`int` + The ID of the application to fetch. + + Raises + ------- + :exc:`.HTTPException` + Retrieving the application failed. + + Returns + ------- + :class:`.Application` + The retrieved application. + """ + state = self._connection + data = await state.http.get_my_application(app_id) + return Application(state=state, data=data) + + async def fetch_partial_application(self, app_id: int, /) -> PartialApplication: + """|coro| + + Retrieves the partial application with the given ID. + + Returns + -------- + :class:`.PartialApplication` + The retrieved application. + """ + state = self._connection + data = await state.http.get_partial_application(app_id) + return PartialApplication(state=state, data=data) + + async def teams(self) -> List[Team]: + """|coro| + + Retrieves all the teams you're a part of. + + .. versionadded:: 2.0 + + Raises + ------- + :exc:`.HTTPException` + Retrieving the teams failed. + + Returns + ------- + List[:class:`.Team`] + The teams you're a part of. + """ + state = self._connection + data = await state.http.get_teams() + return [Team(state=state, data=d) for d in data] + + async def fetch_team(self, team_id: int, /) -> Team: + """|coro| + + Retrieves the team with the given ID. + + .. versionadded:: 2.0 + + Parameters + ----------- + id: :class:`int` + The ID of the team to fetch. + + Raises + ------- + :exc:`.HTTPException` + Retrieving the team failed. + + Returns + ------- + :class:`.Team` + The retrieved team. + """ + state = self._connection + data = await state.http.get_team(team_id) + return Team(state=state, data=data) + async def create_application(self, name: str): """|coro| diff --git a/discord/http.py b/discord/http.py index 553c774af..1c6062f84 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1881,7 +1881,7 @@ class HTTPClient: return self.request(Route('POST', '/applications/{app_id}/transfer', app_id=app_id), json=payload, super_properties_to_track=True) def get_partial_application(self, app_id: Snowflake) -> Response[appinfo.PartialAppInfo]: - return self.request(Route('GET', '/applications/{app_id}/rpc', app_id=app_id), auth=False) + return self.request(Route('GET', '/applications/{app_id}/rpc', app_id=app_id)) def create_app(self, name: str): payload = { @@ -1924,7 +1924,7 @@ class HTTPClient: def edit_team(self, team_id: Snowflake, payload) -> Response[team.Team]: return self.request(Route('PATCH', '/teams/{team_id}', team_id=team_id), json=payload, super_properties_to_track=True) - def delete_application(self, team_id: Snowflake) -> Response[None]: + def delete_team(self, team_id: Snowflake) -> Response[None]: return self.request(Route('POST', '/teams/{app_id}/delete', team_id=team_id), super_properties_to_track=True) def get_team_applications(self, team_id: Snowflake) -> Response[List[appinfo.AppInfo]]: diff --git a/discord/team.py b/discord/team.py index d26ad7048..d57e96245 100644 --- a/discord/team.py +++ b/discord/team.py @@ -143,10 +143,9 @@ class Team: payload['icon'] = '' if owner is not MISSING: payload['owner_user_id'] = owner.id - await self._state.http.edit_team(self.id, payload) - await self._state.http.edit_team(self.id, payload) - self._update(payload) + data = await self._state.http.edit_team(self.id, payload) + self._update(data) async def fetch_members(self) -> List[TeamMember]: """|coro| @@ -179,10 +178,10 @@ class Team: ... @overload - async def invite_member(self, username: str, discriminator: Union[int, str]) -> TeamMember: + async def invite_member(self, username: str, discriminator: str) -> TeamMember: ... - async def invite_member(self, *args: Union[BaseUser, int, str]) -> TeamMember: + async def invite_member(self, *args: Union[BaseUser, str]) -> TeamMember: """|coro| Invites a member to the team. @@ -224,7 +223,7 @@ class Team: The new member. """ username: str - discrim: Union[str, int] + discrim: str if len(args) == 1: user = args[0] if isinstance(user, BaseUser): @@ -241,6 +240,20 @@ class Team: self.members.append(member) return member + async def delete(self) -> None: + """|coro| + + Deletes the team. + + Raises + ------- + Forbidden + You do not have permissions to delete the team. + HTTPException + Deleting the team failed. + """ + await self._state.http.delete_team(self.id) + class TeamMember(BaseUser): """Represents a team member in a team.