@@ -57,6 +57,58 @@ def __name__(self):
57
57
58
58
59
59
class Option :
60
+ """Represents a selectable option for a slash command.
61
+
62
+ Examples
63
+ --------
64
+ Basic usage: ::
65
+
66
+ @bot.slash_command(guild_ids=[...])
67
+ async def hello(
68
+ ctx: discord.ApplicationContext,
69
+ name: Option(str, "Enter your name"),
70
+ age: Option(int, "Enter your age", min_value=1, max_value=99, default=18)
71
+ # passing the default value makes an argument optional
72
+ # you also can create optional argument using:
73
+ # age: Option(int, "Enter your age") = 18
74
+ ):
75
+ await ctx.respond(f"Hello! Your name is {name} and you are {age} years old.")
76
+
77
+ .. versionadded:: 2.0
78
+
79
+ Attributes
80
+ ----------
81
+ input_type: :class:`Any`
82
+ The type of input that is expected for this option.
83
+ description: :class:`str`
84
+ The description of this option.
85
+ Must be 100 characters or fewer.
86
+ name: :class:`str`
87
+ The name of this option visible in the UI.
88
+ Inherits from the variable name if not provided as a parameter.
89
+ choices: Optional[List[Union[:class:`Any`, :class:`OptionChoice`]]]
90
+ The list of available choices for this option.
91
+ Can be a list of values or :class:`OptionChoice` objects (which represent a name:value pair).
92
+ If provided, the input from the user must match one of the choices in the list.
93
+ required: Optional[:class:`bool`]
94
+ Whether this option is required.
95
+ default: Optional[:class:`Any`]
96
+ The default value for this option. If provided, ``required`` will be considered ``False``.
97
+ min_value: Optional[:class:`int`]
98
+ The minimum value that can be entered.
99
+ Only applies to Options with an input_type of ``int`` or ``float``.
100
+ max_value: Optional[:class:`int`]
101
+ The maximum value that can be entered.
102
+ Only applies to Options with an input_type of ``int`` or ``float``.
103
+ autocomplete: Optional[:class:`Any`]
104
+ The autocomplete handler for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
105
+ single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
106
+
107
+ .. note::
108
+
109
+ Does not validate the input value against the autocomplete results.
110
+ """
111
+
60
112
def __init__ (self , input_type : Any , / , description : str = None , ** kwargs ) -> None :
61
113
self .name : Optional [str ] = kwargs .pop ("name" , None )
62
114
self .description = description or "No description provided"
@@ -139,6 +191,19 @@ def __repr__(self):
139
191
140
192
141
193
class OptionChoice :
194
+ """
195
+ Represents a name:value pairing for a selected :class:`Option`.
196
+
197
+ .. versionadded:: 2.0
198
+
199
+ Attributes
200
+ ----------
201
+ name: :class:`str`
202
+ The name of the choice. Shown in the UI when selecting an option.
203
+ value: Optional[Union[:class:`str`, :class:`int`, :class:`float`]]
204
+ The value of the choice. If not provided, will use the value of ``name``.
205
+ """
206
+
142
207
def __init__ (self , name : str , value : Optional [Union [str , int , float ]] = None ):
143
208
self .name = name
144
209
self .value = value if value is not None else name
0 commit comments