nextcord
nextcord copied to clipboard
`typing.Literal`, `nextcord.Range` and `typing.Union` for choices + ranges + channel types
- [x] #589
- [ ] #590
- [x] #591
Summary
use typing.Literal["some", "choices"] instead of SlashOption(choices=["some", "choices"]), nextcord.Range[1, 10] instead of SlashOption(min_value=1, max_value=10) and Union[Textchannel, VoiceChannel] instead of SlashOption(channel_types=[ChannelType.text, ChannelType.voice])
What is the feature request for?
Application commands
The Problem
Currently, using SlashOption has been found to be slightly annoying to work with and pretty verbose in terms of syntax. Having a Range for min/max values and using Literal for choices will be more concise and less janky. Using Union's (typing converts 3.10 piped unions to typing.Union I believe
The Ideal Solution
typing.Literal[1, 2, 3]
nextcord.Range[min, max]
Union[Channel, Classes]
The Current Solution
str: SlashOption(choices=[some, choices])
int/float: SlashOption(min_value=min, max_value=max)
GuildChannel = SlashOption(channel_types=[ChannelType's])
ill working on typing.Literal part for now.
Maybe allowing Enums for choices as well could be useful, especially when there are a lot of options or you are using it elsewhere and want to reduce redundancy.
question, how do you rolling out slash commands?
ill working on
typing.Literalpart for now.
I think Dysta said they are working on literal already (about 5 hours ago). It was on the Discord server.
The relevant code to change would be the CommandOption constructor and/or the CommandOption.get_type method
okay
I plan to split this issue into separate parts and include channel unions
#530 stalls this
This should be moved from TODO because of the linked PR
It seems like the Range aspect is still not implemented so it won't be closed by #678
Anddddd, this is complete!