Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and fixes to ApplicationContext.selected_options and ApplicationContext.unselected_options #953

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Changes from 2 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
19 changes: 11 additions & 8 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ def selected_options(self) -> Optional[List[Dict]]:
-------
Optional[List[Dict]]
A dictionary containing the options and values that were selected by the user when the command was processed, if applicable.
Returns ``None`` if the command has not yet been invoked, or if there are no options defined for that command.
"""
if "options" in self.interaction.data:
return self.interaction.data["options"]
return None
return self.interaction.data.get("options", None)

@property
def unselected_options(self) -> Optional[List[Option]]:
Expand All @@ -197,13 +196,17 @@ def unselected_options(self) -> Optional[List[Option]]:
-------
Optional[List[:class:`.Option`]]
A list of Option objects (if any) that were not selected by the user when the command was processed.
Returns ``None`` if there are no options defined for that command.
"""
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]
]
if self.selected_options:
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]
]
else:
return self.command.options # type: ignore
return None

@property
Expand Down