From d537f5f50fd82deb2a28d3073b824d9b583e0791 Mon Sep 17 00:00:00 2001 From: shea <80988430+px1w@users.noreply.github.com> Date: Mon, 28 Apr 2025 12:41:49 +0000 Subject: [PATCH 1/4] Fix @dm_only() decorator to correctly restrict command to DMs only - Updated the decorator to explicitly disable guild and private channel contexts - Ensured that only DM context is allowed by setting allowed_contexts.dm_channel = True --- discord/app_commands/commands.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index d5b8d93b2..feb204c96 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -2623,6 +2623,11 @@ def dm_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: allowed_contexts = getattr(f, '__discord_app_commands_contexts__', None) or AppCommandContext() f.__discord_app_commands_contexts__ = allowed_contexts # type: ignore # Runtime attribute assignment + # Ensure that only DM context is allowed + allowed_contexts.guild = False # Disable guild context + allowed_contexts.private_channel = False # Disable private channel context + allowed_contexts.dm_channel = True # Enable DM context + allowed_contexts.dm_channel = True return f From b369d35ee6bc78ae08976826640bcafde8ed7be6 Mon Sep 17 00:00:00 2001 From: shea <80988430+px1w@users.noreply.github.com> Date: Mon, 28 Apr 2025 14:09:28 +0100 Subject: [PATCH 2/4] Fixed double statement allowed_contexts.dm_channel = True was stated twice, removed the second one. --- discord/app_commands/commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index feb204c96..8ec67755d 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -2627,8 +2627,7 @@ def dm_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: allowed_contexts.guild = False # Disable guild context allowed_contexts.private_channel = False # Disable private channel context allowed_contexts.dm_channel = True # Enable DM context - - allowed_contexts.dm_channel = True + return f # Check if called with parentheses or not From e9cffcbf451c8f46d0d39d1ab298362ea6bf3339 Mon Sep 17 00:00:00 2001 From: shea <80988430+px1w@users.noreply.github.com> Date: Tue, 29 Apr 2025 12:12:49 +0100 Subject: [PATCH 3/4] Updates guild_install, user_install, private_channel_only and guild_only decorators to explicity include allowed and unallowed contexts. --- discord/app_commands/commands.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index 8ec67755d..3a6f474fe 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -2516,8 +2516,11 @@ def guild_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: allowed_contexts = getattr(f, '__discord_app_commands_contexts__', None) or AppCommandContext() f.__discord_app_commands_contexts__ = allowed_contexts # type: ignore # Runtime attribute assignment - - allowed_contexts.guild = True + + # Ensure that only Guild context is allowed + allowed_contexts.guild = False # Enable guild context + allowed_contexts.private_channel = False # Disable private channel context + allowed_contexts.dm_channel = False # Disable DM context return f @@ -2570,8 +2573,11 @@ def private_channel_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]] else: allowed_contexts = getattr(f, '__discord_app_commands_contexts__', None) or AppCommandContext() f.__discord_app_commands_contexts__ = allowed_contexts # type: ignore # Runtime attribute assignment - - allowed_contexts.private_channel = True + + # Ensure that only Private Channel context is allowed + allowed_contexts.guild = False # Disable guild context + allowed_contexts.private_channel = True # Enable private channel context + allowed_contexts.dm_channel = False # Disable DM context return f @@ -2721,6 +2727,7 @@ def guild_install(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: f.__discord_app_commands_installation_types__ = allowed_installs # type: ignore # Runtime attribute assignment allowed_installs.guild = True + allowed_installs.user = False return f @@ -2771,6 +2778,7 @@ def user_install(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: f.__discord_app_commands_installation_types__ = allowed_installs # type: ignore # Runtime attribute assignment allowed_installs.user = True + allowed_installs.guild = False return f From 7c37e9e84f696438afc04876b81d6f4ed5f9148f Mon Sep 17 00:00:00 2001 From: Danny <1695103+Rapptz@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:52:34 -0400 Subject: [PATCH 4/4] Update discord/app_commands/commands.py --- discord/app_commands/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index 3a6f474fe..f82f7eed7 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -2520,7 +2520,7 @@ def guild_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: # Ensure that only Guild context is allowed allowed_contexts.guild = False # Enable guild context allowed_contexts.private_channel = False # Disable private channel context - allowed_contexts.dm_channel = False # Disable DM context + allowed_contexts.dm_channel = False # Disable DM context return f