Skip to content

Commit 105a3cc

Browse files
authored
Updates and fixes to ApplicationContext.selected_options and ApplicationContext.unselected_options (#953)
* update docstrings, better way to handle retrieving options dict * fix situation where no selected options are chosen
1 parent 217a8fa commit 105a3cc

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

discord/commands/context.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ def selected_options(self) -> Optional[List[Dict]]:
184184
-------
185185
Optional[List[Dict]]
186186
A dictionary containing the options and values that were selected by the user when the command was processed, if applicable.
187+
Returns ``None`` if the command has not yet been invoked, or if there are no options defined for that command.
187188
"""
188-
if "options" in self.interaction.data:
189-
return self.interaction.data["options"]
190-
return None
189+
return self.interaction.data.get("options", None)
191190

192191
@property
193192
def unselected_options(self) -> Optional[List[Option]]:
@@ -197,13 +196,17 @@ def unselected_options(self) -> Optional[List[Option]]:
197196
-------
198197
Optional[List[:class:`.Option`]]
199198
A list of Option objects (if any) that were not selected by the user when the command was processed.
199+
Returns ``None`` if there are no options defined for that command.
200200
"""
201201
if self.command.options is not None: # type: ignore
202-
return [
203-
option
204-
for option in self.command.options # type: ignore
205-
if option.to_dict()["name"] not in [opt["name"] for opt in self.selected_options]
206-
]
202+
if self.selected_options:
203+
return [
204+
option
205+
for option in self.command.options # type: ignore
206+
if option.to_dict()["name"] not in [opt["name"] for opt in self.selected_options]
207+
]
208+
else:
209+
return self.command.options # type: ignore
207210
return None
208211

209212
@property

0 commit comments

Comments
 (0)