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] 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