Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down