@@ -54,6 +54,9 @@ pub struct EditRole<'a> {
5454 #[ serde( rename = "color" ) ]
5555 colour : Option < Colour > ,
5656 #[ serde( skip_serializing_if = "Option::is_none" ) ]
57+ #[ serde( rename = "colors" ) ]
58+ colours : Option < CreateRoleColours > ,
59+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
5760 hoist : Option < bool > ,
5861 #[ serde( skip_serializing_if = "Option::is_none" ) ]
5962 icon : Option < Option < String > > ,
@@ -86,6 +89,7 @@ impl<'a> EditRole<'a> {
8689 colour : Some ( role. colour ) ,
8790 unicode_emoji : role. unicode_emoji . as_ref ( ) . map ( |v| Some ( v. clone ( ) ) ) ,
8891 audit_log_reason : None ,
92+ colours : Some ( role. colours . into ( ) ) ,
8993 // TODO: Do we want to download role.icon?
9094 icon : None ,
9195 }
@@ -97,6 +101,12 @@ impl<'a> EditRole<'a> {
97101 self
98102 }
99103
104+ /// Sets the colours of the role. Supports gradient and holographic role colours.
105+ pub fn colours ( mut self , colours : impl Into < CreateRoleColours > ) -> Self {
106+ self . colours = Some ( colours. into ( ) ) ;
107+ self
108+ }
109+
100110 /// Whether or not to hoist the role above lower-positioned roles in the user list.
101111 pub fn hoist ( mut self , hoist : bool ) -> Self {
102112 self . hoist = Some ( hoist) ;
@@ -150,6 +160,55 @@ impl<'a> EditRole<'a> {
150160 }
151161}
152162
163+ /// The colours of a Discord role, secondary_colour and tertiary_colour may only be set if
164+ /// the [Guild] has the `ENHANCED_ROLE_COLORS` feature.
165+ ///
166+ /// Note: 2024-07-05 - tertiary_colour is currently enforced to be set with a specific pair of
167+ /// primary and secondary colours, for current validation see
168+ /// [Discord docs](https://discord.com/developers/docs/topics/permissions#role-object-role-colors-object).
169+ #[ derive( Clone , Debug , Default , Serialize ) ]
170+ #[ must_use]
171+ #[ allow( clippy:: struct_field_names) ]
172+ pub struct CreateRoleColours {
173+ primary_color : Colour ,
174+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
175+ secondary_color : Option < Colour > ,
176+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
177+ tertiary_color : Option < Colour > ,
178+ }
179+
180+ impl CreateRoleColours {
181+ pub fn new ( primary_colour : Colour ) -> Self {
182+ Self {
183+ primary_color : primary_colour,
184+ secondary_color : None ,
185+ tertiary_color : None ,
186+ }
187+ }
188+
189+ /// Sets the secondary colour for this role.
190+ pub fn secondary_colour ( mut self , secondary_colour : Colour ) -> Self {
191+ self . secondary_color = Some ( secondary_colour) ;
192+ self
193+ }
194+
195+ /// Sets the tertiary colour for this role, see struct documentation for limitations.
196+ pub fn tertiary_colour ( mut self , tertiary_colour : Colour ) -> Self {
197+ self . tertiary_color = Some ( tertiary_colour) ;
198+ self
199+ }
200+ }
201+
202+ impl From < RoleColours > for CreateRoleColours {
203+ fn from ( c : RoleColours ) -> CreateRoleColours {
204+ CreateRoleColours {
205+ primary_color : c. primary_colour ,
206+ secondary_color : c. secondary_colour ,
207+ tertiary_color : c. tertiary_colour ,
208+ }
209+ }
210+ }
211+
153212#[ cfg( feature = "http" ) ]
154213#[ async_trait:: async_trait]
155214impl Builder for EditRole < ' _ > {
0 commit comments