Skip to content

feat(commands): add support for typing.Literal[...] as command choices #2782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Lumabots
Copy link

Summary

permit the usage of choice like so :

@bot.command()
async def test(ctx: discord.ApplicationContext, test: Literal["1", "2"]): ...

instead of needed to do

@bot.command()
@discord.option(name="test", choices=["1", "2"])
async def test(ctx: discord.ApplicationContext, test: ...

or

@bot.command()
async def test(ctx: discord.ApplicationContext, test: discord.Option(str, choices=["1", "2"])): ...

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@Lumabots Lumabots changed the title Added support for typing.Literal[...] to define command choices. feat(commands): add support for typing.Literal[...] as command choices (#1518) May 16, 2025
@Lumabots Lumabots changed the title feat(commands): add support for typing.Literal[...] as command choices (#1518) feat(commands): add support for typing.Literal[...] as command choices May 16, 2025
@Lulalaby Lulalaby requested a review from JustaSqu1d May 17, 2025 13:47
VincentRPS
VincentRPS previously approved these changes May 22, 2025
Co-authored-by: JustaSqu1d <[email protected]>
Signed-off-by: Lumouille <[email protected]>
Copy link
Member

@VincentRPS VincentRPS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@VincentRPS VincentRPS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants