Allow using Enums to define choices for options
This release adds the ability to use Python Enums to define option choices using type hinting.
Old syntax (still works, but no longer the recommended way):
@discord.command(options=[{
"name": "choice",
"description": "Your favorite animal",
"type": CommandOptionType.STRING,
"required": True,
"choices": [
{
"name": "Dog",
"value": "dog"
},
{
"name": "Cat",
"value": "cat"
}
]
}])
def favorite(ctx, choice):
"What is your favorite animal?"
return f"{ctx.author.display_name} chooses {choice}!"
New syntax:
class Animal(enum.Enum):
Dog = "dog"
Cat = "cat"
@discord.command(annotations={"choice": "Your favorite animal"})
def favorite(ctx, choice: Animal):
"What is your favorite animal?"
return f"{ctx.author.display_name} chooses {choice}!"
Additionally, this version now includes Sphinx docs.