From 7222a23b21a45bb03b82e4ed6fdced609a7d53be Mon Sep 17 00:00:00 2001 From: Depreca1ed <70801324+Depreca1ed@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:46:00 +0530 Subject: [PATCH 1/4] Added scopeless kwarg to discord.utils.oauth_url --- discord/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index 905735cfb406..66b661eed1aa 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -328,6 +328,7 @@ def oauth_url( guild: Snowflake = MISSING, redirect_uri: str = MISSING, scopes: Iterable[str] = MISSING, + scopeless: bool = False, disable_guild_select: bool = False, state: str = MISSING, ) -> str: @@ -354,6 +355,8 @@ def oauth_url( An optional valid list of scopes. Defaults to ``('bot', 'applications.commands')``. .. versionadded:: 1.7 + scopeless: :class:`bool` + Whether to have the default scopes in the OAuth2 URL. disable_guild_select: :class:`bool` Whether to disallow the user from changing the guild dropdown. @@ -369,7 +372,8 @@ def oauth_url( The OAuth2 URL for inviting the bot into guilds. """ url = f'https://discord.com/oauth2/authorize?client_id={client_id}' - url += '&scope=' + '+'.join(scopes or ('bot', 'applications.commands')) + if not scopeless: + url += '&scope=' + '+'.join(scopes or ('bot', 'applications.commands')) if permissions is not MISSING: url += f'&permissions={permissions.value}' if guild is not MISSING: From e5b5c17367e8793dc299c7d584450f63e2b11cee Mon Sep 17 00:00:00 2001 From: Depreca1ed <70801324+Depreca1ed@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:51:47 +0530 Subject: [PATCH 2/4] Added versionadded to kwarg --- discord/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 66b661eed1aa..0ccfd99fa14c 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -355,8 +355,6 @@ def oauth_url( An optional valid list of scopes. Defaults to ``('bot', 'applications.commands')``. .. versionadded:: 1.7 - scopeless: :class:`bool` - Whether to have the default scopes in the OAuth2 URL. disable_guild_select: :class:`bool` Whether to disallow the user from changing the guild dropdown. @@ -365,6 +363,10 @@ def oauth_url( The state to return after the authorization. .. versionadded:: 2.0 + scopeless: :class:`bool` + Whether to have the default scopes in the OAuth2 URL. + + .. versionadded:: 2.5 Returns -------- From 74ecd2099a51616d3e7b2bdabd5cdc387c63562c Mon Sep 17 00:00:00 2001 From: Depreca1ed <70801324+Depreca1ed@users.noreply.github.com> Date: Thu, 16 Jan 2025 01:13:36 +0530 Subject: [PATCH 3/4] Corrects the ordering of kwargs with respect to doc-string --- discord/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index 0ccfd99fa14c..25c53b5f38d0 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -328,9 +328,9 @@ def oauth_url( guild: Snowflake = MISSING, redirect_uri: str = MISSING, scopes: Iterable[str] = MISSING, - scopeless: bool = False, disable_guild_select: bool = False, state: str = MISSING, + scopeless: bool = False, ) -> str: """A helper function that returns the OAuth2 URL for inviting the bot into guilds. From c0c8253bd79405e489071b9dfe9821375e879c27 Mon Sep 17 00:00:00 2001 From: Depreca1ed <70801324+Depreca1ed@users.noreply.github.com> Date: Fri, 17 Jan 2025 00:20:57 +0530 Subject: [PATCH 4/4] Allows scopes to be None --- discord/utils.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 25c53b5f38d0..9b6bd59a2ced 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -327,10 +327,9 @@ def oauth_url( permissions: Permissions = MISSING, guild: Snowflake = MISSING, redirect_uri: str = MISSING, - scopes: Iterable[str] = MISSING, + scopes: Optional[Iterable[str]] = MISSING, disable_guild_select: bool = False, state: str = MISSING, - scopeless: bool = False, ) -> str: """A helper function that returns the OAuth2 URL for inviting the bot into guilds. @@ -363,10 +362,6 @@ def oauth_url( The state to return after the authorization. .. versionadded:: 2.0 - scopeless: :class:`bool` - Whether to have the default scopes in the OAuth2 URL. - - .. versionadded:: 2.5 Returns -------- @@ -374,7 +369,7 @@ def oauth_url( The OAuth2 URL for inviting the bot into guilds. """ url = f'https://discord.com/oauth2/authorize?client_id={client_id}' - if not scopeless: + if scopes is not None: url += '&scope=' + '+'.join(scopes or ('bot', 'applications.commands')) if permissions is not MISSING: url += f'&permissions={permissions.value}'