feat(commands): take a backed enum as a command option - #20
Merged
Merged
Conversation
A fixed set of values had to be written as a string option with a choice list beside it — two places to change and one to forget, and the handler still received a bare string it had to validate itself. The framework already resolved backed enums for a component's arguments; a command's options were the one place it did not. Now an enum typed option becomes a string or integer option depending on its backing, every case is offered as a choice, and the handler is given the case. Cases are labelled by their own name, which is a PHP identifier and rarely what a bot wants shown, so an enum may implement Choosable to say how each one reads. A value that is not a case can only come from a client that made one up, since Discord checks a choice against the list it was given. That names the option and the value rather than surfacing a ValueError from deep inside from().
github-actions Bot
pushed a commit
that referenced
this pull request
Sep 2, 2026
## [0.12.0](v0.11.0...v0.12.0) (2026-09-02) ### Features * **commands:** take a backed enum as a command option ([#20](#20)) ([326704b](326704b))
|
🎉 This PR is included in version 0.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A fixed set of values had to be written as a string option with a choice list beside it:
Two places to change and one to forget, and the handler still receives a bare string it has to validate itself.
The framework already resolved backed enums for a component's arguments (
ComponentArgumentResolver); a command's options were the one place it did not. Now:STRINGoption, an int-backed one anINTEGERoption;choices:says otherwise;Naming the cases
A case name is a PHP identifier, in English, and rarely what a bot wants shown —
PlayStationhappens to read well,NorthAmericadoes not. An enum may implementChoosableto say how each one reads:Without it the case name is used, which is at least a name somebody chose.
A value that is not a case
Discord checks a choice against the list it was given, so this can only come from a client that made one up. It names the option and the value rather than surfacing a
ValueErrorfrom deep insidefrom().Also sets
scanDirectoriesfortests/Fixtures— they are excluded from analysis, but a test naming one still has to resolve to something.🤖 Generated with Claude Code