@@ -12,6 +12,8 @@ const PermissionsBitField = require('../util/PermissionsBitField');
1212const { setPosition, resolveColor } = require ( '../util/Util' ) ;
1313
1414let cacheWarningEmitted = false ;
15+ let deprecationEmittedForCreate = false ;
16+ let deprecationEmittedForEdit = false ;
1517
1618/**
1719 * Manages API methods for roles and stores their cache.
@@ -112,11 +114,24 @@ class RoleManager extends CachedManager {
112114 * @returns {?Snowflake }
113115 */
114116
117+ /**
118+ * @typedef {Object } RoleColorsResolvable
119+ * @property {ColorResolvable } primaryColor The primary color of the role
120+ * @property {ColorResolvable } [secondaryColor] The secondary color of the role.
121+ * This will make the role a gradient between the other provided colors
122+ * @property {ColorResolvable } [tertiaryColor] The tertiary color of the role.
123+ * When sending `tertiaryColor` the API enforces the role color to be a holographic style
124+ * with values of `primaryColor = 11127295`, `secondaryColor = 16759788`, and `tertiaryColor = 16761760`.
125+ * These values are available as a constant: `Constants.HolographicStyle`
126+ */
127+
115128 /**
116129 * Options used to create a new role.
117130 * @typedef {Object } RoleCreateOptions
118131 * @property {string } [name] The name of the new role
119132 * @property {ColorResolvable } [color] The data to create the role with
133+ * <warn>This property is deprecated. Use `colors` instead.</warn>
134+ * @property {RoleColorsResolvable } [colors] The colors to create the role with
120135 * @property {boolean } [hoist] Whether or not the new role should be hoisted
121136 * @property {PermissionResolvable } [permissions] The permissions for the new role
122137 * @property {number } [position] The position of the new role
@@ -142,26 +157,61 @@ class RoleManager extends CachedManager {
142157 * // Create a new role with data and a reason
143158 * guild.roles.create({
144159 * name: 'Super Cool Blue People',
145- * color: Colors.Blue,
146160 * reason: 'we needed a role for Super Cool People',
161+ * colors: {
162+ * primaryColor: Colors.Blue,
163+ * },
164+ * })
165+ * .then(console.log)
166+ * .catch(console.error);
167+ * @example
168+ * // Create a role with holographic colors
169+ * guild.roles.create({
170+ * name: 'Holographic Role',
171+ * reason: 'Creating a role with holographic effect',
172+ * colors: {
173+ * primaryColor: Constants.HolographicStyle.Primary,
174+ * secondaryColor: Constants.HolographicStyle.Secondary,
175+ * tertiaryColor: Constants.HolographicStyle.Tertiary,
176+ * },
147177 * })
148178 * .then(console.log)
149179 * .catch(console.error);
150180 */
151181 async create ( options = { } ) {
152- let { name , color , hoist , permissions, position , mentionable , reason , icon, unicodeEmoji } = options ;
153- color &&= resolveColor ( color ) ;
182+ let { permissions, icon } = options ;
183+ const { name , color, hoist , position , mentionable , reason , unicodeEmoji } = options ;
154184 if ( permissions !== undefined ) permissions = new PermissionsBitField ( permissions ) ;
155185 if ( icon ) {
156186 const guildEmojiURL = this . guild . emojis . resolve ( icon ) ?. imageURL ( ) ;
157187 icon = guildEmojiURL ? await resolveImage ( guildEmojiURL ) : await resolveImage ( icon ) ;
158188 if ( typeof icon !== 'string' ) icon = undefined ;
159189 }
160190
191+ let colors = options . colors && {
192+ primary_color : resolveColor ( options . colors . primaryColor ) ,
193+ secondary_color : options . colors . secondaryColor && resolveColor ( options . colors . secondaryColor ) ,
194+ tertiary_color : options . colors . tertiaryColor && resolveColor ( options . colors . tertiaryColor ) ,
195+ } ;
196+
197+ if ( color !== undefined ) {
198+ if ( ! deprecationEmittedForCreate ) {
199+ process . emitWarning ( `Passing "color" to RoleManager#create() is deprecated. Use "colors" instead.` ) ;
200+ }
201+
202+ deprecationEmittedForCreate = true ;
203+
204+ colors = {
205+ primary_color : resolveColor ( color ) ,
206+ secondary_color : null ,
207+ tertiary_color : null ,
208+ } ;
209+ }
210+
161211 const data = await this . client . rest . post ( Routes . guildRoles ( this . guild . id ) , {
162212 body : {
163213 name,
164- color ,
214+ colors ,
165215 hoist,
166216 permissions,
167217 mentionable,
@@ -210,9 +260,29 @@ class RoleManager extends CachedManager {
210260 if ( typeof icon !== 'string' ) icon = undefined ;
211261 }
212262
263+ let colors = options . colors && {
264+ primary_color : resolveColor ( options . colors . primaryColor ) ,
265+ secondary_color : options . colors . secondaryColor && resolveColor ( options . colors . secondaryColor ) ,
266+ tertiary_color : options . colors . tertiaryColor && resolveColor ( options . colors . tertiaryColor ) ,
267+ } ;
268+
269+ if ( options . color !== undefined ) {
270+ if ( ! deprecationEmittedForEdit ) {
271+ process . emitWarning ( `Passing "color" to RoleManager#edit() is deprecated. Use "colors" instead.` ) ;
272+ }
273+
274+ deprecationEmittedForEdit = true ;
275+
276+ colors = {
277+ primary_color : resolveColor ( options . color ) ,
278+ secondary_color : null ,
279+ tertiary_color : null ,
280+ } ;
281+ }
282+
213283 const body = {
214284 name : options . name ,
215- color : options . color === undefined ? undefined : resolveColor ( options . color ) ,
285+ colors ,
216286 hoist : options . hoist ,
217287 permissions : options . permissions === undefined ? undefined : new PermissionsBitField ( options . permissions ) ,
218288 mentionable : options . mentionable ,
0 commit comments