Call expression in type expression when defining list of allowed values for slash_command parameter #2748
-
I was wondering if there is a python-spec compliant way of creating slash commands with a restricted list of values for a given parameter I have a situation like this here: @bot.slash_command()
async def recommend(
context: ApplicationContext,
genre: Option(str, description="Choose a genre", choices=["thriller", "horror", "action"]),
):
... At runtime this works fine, but due to the nature of the type of genre being an expression Pyright will warn you |
Beta Was this translation helpful? Give feedback.
Answered by
JustaSqu1d
Mar 22, 2025
Replies: 1 comment 1 reply
-
You can use the from discord import option
from typing import Literal
@bot.slash_command()
@option("option_name", type=str, description="Choose a genre", choices=["thriller", "horror", "action"])
async def command(ctx, option_name: Literal["category1", "category2", "category3"]):
... I hope this answers your question. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
seyfu-t
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
@option
decorator instead.I hope this answers your question.