Client
- class discordoauth2.Client(id, secret, redirect, bot_token=None)
- Parameters:
- from_access_token(access_token)
Creates a
discordoauth2.PartialAccessTokenobject from a code. This is useful so you can store thePartialAccessToken.tokenand then continue using it.- Parameters:
access_token (str) – The code from oauth2, it is the code paramater on successful return redirect urls from discord’s oauth2.
- Returns:
- exchange_code(code)
Converts a code from the redirect url into a
discordoauth2.AccessToken- Parameters:
code (str) – code paramater from OAuth2 redirect URL
- Returns:
- Raises:
discordoauth2.exceptions.HTTPException – The request failed, usally because the client ID, client, secret, redirect or code is incorrect
discordoauth2.exceptions.RateLimited – You’re being rate limited.
- refresh_token(refresh_token)
Converts a refresh token into a new
discordoauth2.AccessToken. You should store the refresh token and access token, so you can renew the access token when it expires.- Parameters:
refresh_token (str) – The refresh token, can be found from
discordoauth2.AccessToken.refresh_token- Returns:
- Raises:
discordoauth2.exceptions.HTTPException – The request failed, usally because the client ID, client, secret, redirect or code is incorrect
discordoauth2.exceptions.RateLimited – You’re being rate limited.
- client_credentails_grant(scope)
Creates an
discordoauth2.AccessTokenon behalf of the application’s owner.- Parameters:
- Returns:
- Raises:
discordoauth2.exceptions.HTTPException – The request failed, usally because the client ID, client, secret, redirect or code is incorrect
discordoauth2.exceptions.RateLimited – You’re being rate limited.
Warning
If the application is owned by a team, you can only request for the
identifyscope. You can also requestapplications.commands.update, but the library does not support it yet.``- revoke_token(token, token_type=None)
Revokes an OAuth2 token related to the client.
New in version 1.1.
- Parameters:
- Raises:
discordoauth2.exceptions.HTTPException – The request failed, usally because the client ID, client, secret, redirect or code is incorrect
discordoauth2.exceptions.RateLimited – You’re being rate limited.
- update_linked_roles_metadata(metadata)
Updates the application’s linked roles metadata, requires bot token to have been provided.
New in version 1.1.
- Parameters:
metadata (dict) – Should be a list of application role connection metadata
Note
The bot token is required to update metadata.
- generate_uri(metadata)
Creates an authorization uri with client information prefilled.
New in version 1.2.
- Parameters:
scope (Union[str, list[str]]) – A list, or space-seperated string for the authorization scope
state (Optional[str]) – State parameter. It is recommended for security.
skip_prompt (Optional[bool]) – Doesn’t require the end user to reauthorize if they’ve already authorized you app before. Defaults to
False.response_type (Optional[Literal["code", "token"]]) – either code, or token. token means the server can’t access it, but the client can use it without converting.
guild_id (Optional[Union[int, str]]) – the guild ID to add a bot/webhook.
disable_guild_select (Optional[bool]) – wether to allow the authorizing user to change the selected guild
permissions (Optional[int]) – the permission bitwise integer for the bot being added.