diff --git a/disnake/app_commands.py b/disnake/app_commands.py index e3ba692319..38d83a0ca7 100644 --- a/disnake/app_commands.py +++ b/disnake/app_commands.py @@ -675,10 +675,15 @@ def _install_types_with_default(self) -> Optional[ApplicationInstallTypes]: @property def _contexts_with_default(self) -> Optional[InteractionContextTypes]: - # (same logic as `_install_types_with_default`, but without a fallback for contexts) - if self.contexts is None and not isinstance(self, _APIApplicationCommandMixin): - if self._default_contexts is not None: - return self._default_contexts + # (basically the same logic as `_install_types_with_default`, but without a fallback) + if ( + self.contexts is None + and not isinstance(self, _APIApplicationCommandMixin) + and self._default_contexts is not None + # only use default if legacy `dm_permission` wasn't set + and self._dm_permission is None + ): + return self._default_contexts return self.contexts diff --git a/tests/ext/commands/test_base_core.py b/tests/ext/commands/test_base_core.py index 045de1e220..ac6b5ee93b 100644 --- a/tests/ext/commands/test_base_core.py +++ b/tests/ext/commands/test_base_core.py @@ -1,5 +1,7 @@ # SPDX-License-Identifier: MIT +import warnings + import pytest import disnake @@ -131,6 +133,7 @@ async def c(inter) -> None: ... assert c.body.to_dict().get("contexts") == [1] + assert "dm_permission" not in c.body.to_dict() def test_decorator_override(self, bot: commands.InteractionBot) -> None: @commands.contexts(private_channel=True) @@ -147,6 +150,17 @@ async def c(inter: disnake.GuildCommandInteraction) -> None: assert c.body.to_dict().get("contexts") == [0] + def test_dm_permission(self, bot: commands.InteractionBot) -> None: + with warnings.catch_warnings(record=True): + + @bot.slash_command(dm_permission=False) + async def c(inter) -> None: + ... + + # if dm_permission was set, the `contexts` default shouldn't apply + assert c.body.to_dict().get("contexts") is None + assert c.body.to_dict().get("dm_permission") is False + def test_localization_copy() -> None: class Cog(commands.Cog):