diff --git a/discord/commands/context.py b/discord/commands/context.py index 8ba3f73aa0..9e36880cc4 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -24,7 +24,7 @@ """ from __future__ import annotations -from typing import TYPE_CHECKING, Optional, TypeVar, Union +from typing import TYPE_CHECKING, Optional, TypeVar, Union, Dict, List import discord.abc from discord.interactions import InteractionMessage @@ -176,6 +176,36 @@ def voice_client(self) -> Optional[VoiceProtocol]: def response(self) -> InteractionResponse: return self.interaction.response + @property + def selected_options(self) -> Optional[List[Dict]]: + """The options and values that were selected by the user when sending the command. + + Returns + ------- + Optional[List[Dict]] + A dictionary containing the options and values that were selected by the user when the command was processed, if applicable. + """ + if "options" in self.interaction.data: + return self.interaction.data["options"] + return None + + @property + def unselected_options(self) -> Optional[List[Option]]: + """The options that were not provided by the user when sending the command. + + Returns + ------- + Optional[List[:class:`.Option`]] + A list of Option objects (if any) that were not selected by the user when the command was processed. + """ + if self.command.options is not None: # type: ignore + return [ + option + for option in self.command.options # type: ignore + if option.to_dict()["name"] not in [opt["name"] for opt in self.selected_options] + ] + return None + @property def respond(self) -> Callable[..., Awaitable[Union[Interaction, WebhookMessage]]]: """Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response