Skip to content

Commit 328e5c7

Browse files
Clarify docs, allow a list of strings for choices
1 parent 9045b95 commit 328e5c7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

discord_slash/utils/manage_commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ def create_option(name: str,
156156
:param required: Whether this option is required.
157157
:param choices: Choices of the option. Can be empty.
158158
:return: dict
159+
160+
``choices`` must either be a list of `option type dicts <https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice>`_
161+
or a list of single string values.
159162
"""
160163
if not isinstance(option_type, int) or isinstance(option_type, bool): #Bool values are a subclass of int
161164
original_type = option_type
162165
option_type = SlashCommandOptionType.from_type(original_type)
163166
if option_type is None:
164167
raise IncorrectType(f"The type {original_type} is not recognized as a type that Discord accepts for slash commands.")
168+
choices = [choice if isinstance(choice, dict) else {"name": choice, "value": choice} for choice in choices]
165169
return {
166170
"name": name,
167171
"description": description,

0 commit comments

Comments
 (0)