-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Support all Select Menu types #2047
Comments
I'll give this a shot! |
it seems that #2051 will solve this |
@zeylahellyer, sorry if this is not the right place, but I figured it's best to continue discussing potential implementations here now that the initial implementation PR is closed. To clarify, when you mention making pub struct SelectMenu {
pub custom_id: String,
pub disabled: bool,
pub max_values: Option<u8>,
pub min_values: Option<u8>,
pub placeholder: Option<String>,
// The (de-)serialization would, of course, flatten the enum below
pub data: SelectMenuData,
}
pub enum SelectMenuData {
Text {
options: Vec<SelectMenuOption>,
},
Channel {
channel_types: Option<Vec<ChannelType>>,
}
// ...
} Considering this update would also move the existing options to a new enum variant (and out of the structure), would this be too big of a breaking change? I know Twilight is still pre-1.0, but considering a lot of bots will be affected by this, it might be worth documenting the required changes somewhere (e.g. in the changelog). |
I would like to help implementing this if anyone here needs any |
i'd prefer that the enums wrapped over structs instead of being enum structs, something like pub enum SelectMenuData {
Text(Vec<SelectMenuOption>),
Channel(Option<Vec<ChannelType>>),
// ...
} if theres only one field, or like https://api.twilight.rs/twilight_model/application/interaction/enum.InteractionData.html if theres multiple, its more versatile that way |
In addition to moving multi-field structs into separate structs, I'd consider boxing some / most structs, as they could easily increase the enum size for all other components, otherwise (also outlined in the RFC I opened). There's only a potential problem with API stability if we inline variants that only have a single field (even if we box that). While it doesn't matter with the current approach of having exhaustive structs, It might become necessary to create "constructors" for those structs and mark them as |
making a struct |
Indeed, that's why I suggested it might be required in the future. Without marking a struct as non-exhaustive, adding new fields is always a breaking change. I.e., if Discord adds a new parameter within the same API version, twilight would have to go Of course, the Again, this is something for the |
it makes more sense now, i agree we should mark most structs and enums alternatively, and this isnt very common but it solves the issue, we can separate required fields (params of // exhaustive because dapi shouldnt change these fields
struct Foo {
required: u8,
optional: FooOptional,
}
#[non_exhaustive]
#[derive(Default)]
struct FooOptional {
s: Option<String>,
}
// constructed like
let mut foo = Foo {
required: 0,
optional: FooOptional::default(),
};
foo.optional.s = Some("foo".to_owned()); // not breaking because dapi shouldnt remove fields, only add non-required fields (right?)
// or
Foo {
required: 0,
optional: FooOptional {
s: Some("foo".to_owned()),
..Default::default()
},
}; |
With #2219 merged, is there anything left for this issue? |
i'll close this assuming no, feel free to reopen if theres anything left |
Select Menus now support 5 different types:
3
- Only type that supports & requires theoptions
field currently.5
6
7
8
- Only type that supports the optionalchannel_types
field.All but the String Select type supports and returns resolved data in interaction payload.
Reference: Discord Docs
The text was updated successfully, but these errors were encountered: