disnake icon indicating copy to clipboard operation
disnake copied to clipboard

Support `Annotated` in slash command parameters

Open Enegg opened this issue 3 months ago • 1 comments

Summary

Allow using typing.Annotated in slash command parameters to specify numeric ranges and string length limits.

What is the feature request for?

disnake.ext.commands

The Problem

Similarly to #1422, we could add direct support for using Annotated in slash command parameters, like name: Annotated[str, 2, 32] and number: Annotated[float, 10, 15.5].

The library currently uses two dataclasses and some metaclass magic to implement Range and String, and circumvents the type checker incompatibility by aliasing these two types to Annotated (under TYPE_CHECKING). We could go a step further and actually make them be Annotated, possibly simplifying the implementation.

The Ideal Solution

Support Annotated for annotating string and numeric parameters, alias Range and String to Annotated at runtime; possibly also add support for annotated-types

The Current Solution

null

Additional Context

No response

Enegg avatar Oct 12 '25 13:10 Enegg

In that case I think Annotated[int, Range(10, 15)] might be preferable, but we can definitely bikeshed this a lot. c: More generally, I wouldn't be opposed to supporting thing: Annotated[str, commands.Param(...)] in addition to thing: str = commands.Param(...), pretty sure @onerandomusername proposed that recently?

shiftinv avatar Oct 12 '25 16:10 shiftinv