mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-08-18 17:10:32 +00:00
Add state parameter to utils.oauth_url
Co-authored-by: Danny <Rapptz@users.noreply.github.com>
This commit is contained in:
parent
66881ba458
commit
40f12c8a00
@ -288,13 +288,14 @@ def oauth_url(
|
|||||||
redirect_uri: str = MISSING,
|
redirect_uri: str = MISSING,
|
||||||
scopes: Iterable[str] = MISSING,
|
scopes: Iterable[str] = MISSING,
|
||||||
disable_guild_select: bool = False,
|
disable_guild_select: bool = False,
|
||||||
|
state: str = MISSING,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""A helper function that returns the OAuth2 URL for inviting the bot
|
"""A helper function that returns the OAuth2 URL for inviting the bot
|
||||||
into guilds.
|
into guilds.
|
||||||
|
|
||||||
.. versionchanged:: 2.0
|
.. versionchanged:: 2.0
|
||||||
|
|
||||||
``permissions``, ``guild``, ``redirect_uri``, and ``scopes`` parameters
|
``permissions``, ``guild``, ``redirect_uri``, ``scopes`` and ``state`` parameters
|
||||||
are now keyword-only.
|
are now keyword-only.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -315,6 +316,10 @@ def oauth_url(
|
|||||||
disable_guild_select: :class:`bool`
|
disable_guild_select: :class:`bool`
|
||||||
Whether to disallow the user from changing the guild dropdown.
|
Whether to disallow the user from changing the guild dropdown.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
state: :class:`str`
|
||||||
|
The state to return after the authorization.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
@ -328,12 +333,15 @@ def oauth_url(
|
|||||||
url += f'&permissions={permissions.value}'
|
url += f'&permissions={permissions.value}'
|
||||||
if guild is not MISSING:
|
if guild is not MISSING:
|
||||||
url += f'&guild_id={guild.id}'
|
url += f'&guild_id={guild.id}'
|
||||||
if redirect_uri is not MISSING:
|
|
||||||
from urllib.parse import urlencode
|
|
||||||
|
|
||||||
url += '&response_type=code&' + urlencode({'redirect_uri': redirect_uri})
|
|
||||||
if disable_guild_select:
|
if disable_guild_select:
|
||||||
url += '&disable_guild_select=true'
|
url += '&disable_guild_select=true'
|
||||||
|
if redirect_uri is not MISSING or state is not MISSING:
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
if redirect_uri is not MISSING:
|
||||||
|
url += '&response_type=code&' + urlencode({'redirect_uri': redirect_uri})
|
||||||
|
if state is not MISSING:
|
||||||
|
url += f'&{urlencode({"state": state})}'
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user