Skip to content

Commit 5a87804

Browse files
authored
Merge pull request #99 from AnotherCat/improve-create_option
Clarify docs, allow a list of strings for choices
2 parents 97edea0 + 7f5464a commit 5a87804

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

discord_slash/utils/manage_commands.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,17 @@ 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+
.. note::
161+
``choices`` must either be a list of `option type dicts <https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice>`_
162+
or a list of single string values.
159163
"""
160164
if not isinstance(option_type, int) or isinstance(option_type, bool): #Bool values are a subclass of int
161165
original_type = option_type
162166
option_type = SlashCommandOptionType.from_type(original_type)
163167
if option_type is None:
164168
raise IncorrectType(f"The type {original_type} is not recognized as a type that Discord accepts for slash commands.")
169+
choices = [choice if isinstance(choice, dict) else {"name": choice, "value": choice} for choice in choices]
165170
return {
166171
"name": name,
167172
"description": description,

0 commit comments

Comments
 (0)