diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index 6c6880ed4..ed5217da9 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -40,7 +40,7 @@ from .errors import ( ) from ..errors import ClientException from ..enums import AppCommandType, InteractionType -from ..utils import MISSING +from ..utils import MISSING, _get_as_snowflake if TYPE_CHECKING: from ..types.interactions import ApplicationCommandInteractionData, ApplicationCommandInteractionDataOption @@ -671,8 +671,8 @@ class CommandTree(Generic[ClientT]): async def _call_context_menu(self, interaction: Interaction, data: ApplicationCommandInteractionData, type: int): name = data['name'] - guild_id = interaction.guild_id - ctx_menu = self._context_menus.get((name, guild_id, type)) or self._context_menus.get((name, None, type)) + guild_id = _get_as_snowflake(data, 'guild_id') + ctx_menu = self._context_menus.get((name, guild_id, type)) if ctx_menu is None: raise CommandNotFound(name, [], AppCommandType(type)) @@ -729,14 +729,17 @@ class CommandTree(Generic[ClientT]): parents: List[str] = [] name = data['name'] - command = self._global_commands.get(name) - if interaction.guild_id: + + command_guild_id = _get_as_snowflake(data, 'guild_id') + if command_guild_id: try: - guild_commands = self._guild_commands[interaction.guild_id] + guild_commands = self._guild_commands[command_guild_id] except KeyError: - pass + command = None else: - command = guild_commands.get(name) or command + command = guild_commands.get(name) + else: + command = self._global_commands.get(name) # If it's not found at this point then it's not gonna be found at any point if command is None: diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 765b466c7..a2c5fd4d0 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -122,6 +122,7 @@ ApplicationCommandInteractionDataOption = Union[ class _BaseApplicationCommandInteractionDataOptional(TypedDict, total=False): resolved: ResolvedData + guild_id: Snowflake class _BaseApplicationCommandInteractionData(_BaseApplicationCommandInteractionDataOptional):