@@ -14,7 +14,9 @@ def __init__(self, access_token, client) -> None:
1414
1515 async def revoke (self ):
1616 """Shorthand for `Client.revoke_token` with the `PartialAccessToken`'s access token."""
17- return await self .client .revoke_token (self .token , token_type = "access_token" )
17+ return await self .client .revoke_token (
18+ self .token , token_type = "access_token"
19+ )
1820
1921 async def fetch_identify (self ) -> dict :
2022 """Retrieves the user's [user object](https://discord.com/developers/docs/resources/user#user-object).
@@ -37,7 +39,9 @@ async def fetch_identify(self) -> dict:
3739 retry_after = response .json ()["retry_after" ],
3840 )
3941 else :
40- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
42+ raise Exceptions .HTTPException (
43+ f"Unexpected HTTP { response .status } "
44+ )
4145
4246 async def fetch_connections (self ) -> list [dict ]:
4347 """Retrieves a list of [connection object](https://discord.com/developers/docs/resources/user#connection-object)s the user has linked. Requires the `connections` scope"""
@@ -58,7 +62,9 @@ async def fetch_connections(self) -> list[dict]:
5862 retry_after = response .json ()["retry_after" ],
5963 )
6064 else :
61- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
65+ raise Exceptions .HTTPException (
66+ f"Unexpected HTTP { response .status } "
67+ )
6268
6369 async def fetch_guilds (self ) -> list [dict ]:
6470 """Retrieves a list of [partial guild](https://discord.com/developers/docs/resources/user#get-current-user-guilds-example-partial-guild)s the user is in. Requires the `guilds` scope"""
@@ -80,7 +86,9 @@ async def fetch_guilds(self) -> list[dict]:
8086 retry_after = response .json ()["retry_after" ],
8187 )
8288 else :
83- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
89+ raise Exceptions .HTTPException (
90+ f"Unexpected HTTP { response .status } "
91+ )
8492
8593 async def fetch_guild_member (self , guild_id : int ) -> dict :
8694 """Retrieves the user's [guild member object](https://discord.com/developers/docs/resources/guild#guild-member-object) in a specific guild. Requires the `guilds.members.read` scope
@@ -99,14 +107,18 @@ async def fetch_guild_member(self, guild_id: int) -> dict:
99107 f"this AccessToken does not have the nessasary scope."
100108 )
101109 elif response .status == 404 :
102- raise Exceptions .HTTPException (f"user is not in this guild." )
110+ raise Exceptions .HTTPException (
111+ f"user is not in this guild."
112+ )
103113 elif response .status == 429 :
104114 raise Exceptions .RateLimited (
105115 f"You are being Rate Limited. Retry after: { response .json ()['retry_after' ]} " ,
106116 retry_after = response .json ()["retry_after" ],
107117 )
108118 else :
109- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
119+ raise Exceptions .HTTPException (
120+ f"Unexpected HTTP { response .status } "
121+ )
110122
111123 async def join_guild (
112124 self ,
@@ -129,7 +141,9 @@ async def join_guild(
129141 async with aiohttp .ClientSession () as session :
130142 async with session .put (
131143 f"https://discord.com/api/v10/guilds/{ guild_id } /members/{ user_id } " ,
132- headers = {"authorization" : f"Bot { self .client ._AsyncClient__bot_token } " },
144+ headers = {
145+ "authorization" : f"Bot { self .client ._AsyncClient__bot_token } "
146+ },
133147 json = {
134148 "access_token" : self .token ,
135149 "nick" : nick ,
@@ -139,7 +153,9 @@ async def join_guild(
139153 },
140154 ) as response :
141155 if response .status == 204 :
142- raise Exceptions .HTTPException (f"member is already in the guild." )
156+ raise Exceptions .HTTPException (
157+ f"member is already in the guild."
158+ )
143159 elif response .ok :
144160 return await response .json ()
145161 elif response .status == 401 :
@@ -156,7 +172,9 @@ async def join_guild(
156172 retry_after = response .json ()["retry_after" ],
157173 )
158174 else :
159- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
175+ raise Exceptions .HTTPException (
176+ f"Unexpected HTTP { response .status } "
177+ )
160178
161179 async def fetch_metadata (self ):
162180 """Retrieves the user's [metadata](https://discord.com/developers/docs/resources/user#application-role-connection-object) for this application. Requires the `role_connections.write` scope"""
@@ -177,7 +195,9 @@ async def fetch_metadata(self):
177195 retry_after = response .json ()["retry_after" ],
178196 )
179197 else :
180- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
198+ raise Exceptions .HTTPException (
199+ f"Unexpected HTTP { response .status } "
200+ )
181201
182202 async def update_metadata (
183203 self , platform_name : str = None , username : str = None , ** metadata
@@ -205,7 +225,8 @@ def metadataTypeHook(item):
205225 "platform_name" : platform_name ,
206226 "platform_username" : username ,
207227 "metadata" : {
208- key : metadataTypeHook (value ) for key , value in metadata .items ()
228+ key : metadataTypeHook (value )
229+ for key , value in metadata .items ()
209230 },
210231 },
211232 ) as response :
@@ -221,7 +242,9 @@ def metadataTypeHook(item):
221242 retry_after = response .json ()["retry_after" ],
222243 )
223244 else :
224- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
245+ raise Exceptions .HTTPException (
246+ f"Unexpected HTTP { response .status } "
247+ )
225248
226249 async def clear_metadata (self ):
227250 """Clears the user's metadata for this application. Requires the `role_connections.write` scope"""
@@ -243,13 +266,16 @@ async def clear_metadata(self):
243266 retry_after = response .json ()["retry_after" ],
244267 )
245268 else :
246- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
269+ raise Exceptions .HTTPException (
270+ f"Unexpected HTTP { response .status } "
271+ )
247272
248273
249274class AsyncAccessToken (AsyncPartialAccessToken ):
250275 def __init__ (self , data , client ) -> None :
251276 super ().__init__ (data ["access_token" ], client )
252277
278+ self .id_token : Optional [str ] = data .get ("id_token" )
253279 self .expires : int = data .get ("expires_in" )
254280 self .scope : list [str ] = data .get ("scope" , "" ).split (" " )
255281 self .refresh_token : str = data .get ("refresh_token" )
@@ -264,7 +290,9 @@ async def revoke_refresh_token(self):
264290
265291
266292class AsyncClient :
267- def __init__ (self , id : int , secret : str , redirect : str , bot_token : str = None ):
293+ def __init__ (
294+ self , id : int , secret : str , redirect : str , bot_token : str = None
295+ ):
268296 """Represents a Discord Application. Create an application on the [Developer Portal](https://discord.com/developers/applications)
269297
270298 id: The application's ID
@@ -300,7 +328,9 @@ async def update_linked_roles_metadata(self, metadata: list[dict]):
300328 retry_after = response .json ()["retry_after" ],
301329 )
302330 else :
303- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
331+ raise Exceptions .HTTPException (
332+ f"Unexpected HTTP { response .status } "
333+ )
304334
305335 def from_access_token (self , access_token : str ) -> AsyncPartialAccessToken :
306336 """Creates a `PartialAccessToken` from a access token string.
@@ -337,7 +367,9 @@ async def exchange_code(self, code: str) -> AsyncAccessToken:
337367 retry_after = response .json ()["retry_after" ],
338368 )
339369 else :
340- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
370+ raise Exceptions .HTTPException (
371+ f"Unexpected HTTP { response .status } "
372+ )
341373
342374 async def refresh_token (self , refresh_token : str ) -> AsyncAccessToken :
343375 """Converts a refresh token into a new `AccessToken`
@@ -366,17 +398,24 @@ async def refresh_token(self, refresh_token: str) -> AsyncAccessToken:
366398 retry_after = response .json ()["retry_after" ],
367399 )
368400 else :
369- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
401+ raise Exceptions .HTTPException (
402+ f"Unexpected HTTP { response .status } "
403+ )
370404
371- async def client_credentails_grant (self , scope : list [str ]) -> AsyncAccessToken :
405+ async def client_credentails_grant (
406+ self , scope : list [str ]
407+ ) -> AsyncAccessToken :
372408 """Creates an `AccessToken` on behalf of the application's owner. If the owner is a team, then only `identify` and `applications.commands.update` are allowed.
373409
374410 scope: list of string scopes to authorize.
375411 """
376412 async with aiohttp .ClientSession () as session :
377413 async with session .post (
378414 "https://discord.com/api/v10/oauth2/token" ,
379- data = {"grant_type" : "client_credentials" , "scope" : " " .join (scope )},
415+ data = {
416+ "grant_type" : "client_credentials" ,
417+ "scope" : " " .join (scope ),
418+ },
380419 auth = aiohttp .BasicAuth (str (self .id ), self .__secret ),
381420 ) as response :
382421 if response .ok :
@@ -391,7 +430,9 @@ async def client_credentails_grant(self, scope: list[str]) -> AsyncAccessToken:
391430 retry_after = response .json ()["retry_after" ],
392431 )
393432 else :
394- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
433+ raise Exceptions .HTTPException (
434+ f"Unexpected HTTP { response .status } "
435+ )
395436
396437 async def revoke_token (self , token : str , token_type : str = None ):
397438 """Revokes a OAuth2 token related to the client.
@@ -417,7 +458,9 @@ async def revoke_token(self, token: str, token_type: str = None):
417458 retry_after = response .json ()["retry_after" ],
418459 )
419460 else :
420- raise Exceptions .HTTPException (f"Unexpected HTTP { response .status } " )
461+ raise Exceptions .HTTPException (
462+ f"Unexpected HTTP { response .status } "
463+ )
421464
422465 def generate_uri (
423466 self ,
0 commit comments