Skip to content

Commit 4bdb4ca

Browse files
committed
feat(docs): Documented InteractionDataOption
1 parent 65f56e1 commit 4bdb4ca

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

discord/interactions.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,7 @@ def command(self) -> Optional[Union['SlashCommand', 'MessageCommand', 'UserComma
945945
@property
946946
def focused_option(self) -> 'InteractionDataOption':
947947
""":class:`~discord.InteractionDataOption`: Returns the currently focused option."""
948-
for option in self.data.options:
949-
if option.focused:
950-
return option
948+
return self.focused
951949

952950
@property
953951
def focused_option_name(self) -> str:
@@ -1120,6 +1118,18 @@ def __new__(cls, *args, **kwargs):
11201118

11211119

11221120
class InteractionDataOption:
1121+
"""
1122+
Represents a slash-command option passed via a command.
1123+
By default, you only get in contact with this using :attr:`~discord.AutoCompleteInteraction.focused_option`.
1124+
1125+
Attributes
1126+
-----------
1127+
name: :class:`str`
1128+
The name of the option
1129+
type: :class:`~discord.OptionType`
1130+
The type of the option
1131+
1132+
"""
11231133
def __init__(self, *, state, data, guild=None, **kwargs):
11241134
self._state = state
11251135
self._data = data
@@ -1130,6 +1140,7 @@ def __init__(self, *, state, data, guild=None, **kwargs):
11301140

11311141
@property
11321142
def value(self) -> Optional[Union[str, int, float]]:
1143+
"""Union[:class:`str`, :class:`int`, :class:`float`]: Returns the value of the option (what the user passed)"""
11331144
value = self._data.get('value', None)
11341145
if value:
11351146
if isinstance(value, bool): # because booleans are integers too
@@ -1144,10 +1155,12 @@ def value(self) -> Optional[Union[str, int, float]]:
11441155

11451156
@property
11461157
def focused(self) -> bool:
1147-
return bool(self._data.get('focused', False))
1158+
""":class:`bool`: Whether this option is currently focused (for autocomplete)"""
1159+
return self._data.get('focused', False)
11481160

11491161
@property
11501162
def options(self) -> Optional[List['InteractionDataOption']]:
1163+
"""Optional[List[:class:`InteractionDataOption`]]: For sub-command (groups) the sub-command or the actual options"""
11511164
options = self._data.get('options', [])
11521165
return [InteractionDataOption(state=self._state, data=option, guild=self._guild) for option in options]
11531166

docs/Interactions/data-models.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ ModalSubmitInteraction
4949
:inherited-members:
5050
:exclude-members: defer, respond_with_modal, from_type
5151

52-
5352
Localizations
5453
~~~~~~~~~~~~~~~
5554

@@ -58,3 +57,11 @@ Localizations
5857
.. autoclass:: Localizations()
5958
:members:
6059
:inherited-members:
60+
61+
InteractionDataOption
62+
~~~~~~~~~~~~~~~~~~~~~~~
63+
64+
.. attibutetable:: discord.interactions.InteractionDataOption
65+
66+
.. autoclass:: discord.interactions.InteractionDataOption()
67+
:members:

0 commit comments

Comments
 (0)