@@ -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.
@@ -128,6 +130,7 @@ class RoleManager extends CachedManager {
128130 * @typedef {Object } RoleCreateOptions
129131 * @property {string } [name] The name of the new role
130132 * @property {ColorResolvable } [color] The data to create the role with
133+ * <warn>This property is deprecated. Use `colors` instead.</warn>
131134 * @property {RoleColorsResolvable } [colors] The colors to create the role with
132135 * @property {boolean } [hoist] Whether or not the new role should be hoisted
133136 * @property {PermissionResolvable } [permissions] The permissions for the new role
@@ -176,23 +179,35 @@ class RoleManager extends CachedManager {
176179 * .catch(console.error);
177180 */
178181 async create ( options = { } ) {
179- let { permissions, color , icon } = options ;
180- const { name, hoist, position, mentionable, reason, unicodeEmoji } = options ;
182+ let { permissions, icon } = options ;
183+ const { name, color , hoist, position, mentionable, reason, unicodeEmoji } = options ;
181184 if ( permissions !== undefined ) permissions = new PermissionsBitField ( permissions ) ;
182185 if ( icon ) {
183186 const guildEmojiURL = this . guild . emojis . resolve ( icon ) ?. imageURL ( ) ;
184187 icon = guildEmojiURL ? await resolveImage ( guildEmojiURL ) : await resolveImage ( icon ) ;
185188 if ( typeof icon !== 'string' ) icon = undefined ;
186189 }
187190
188- color &&= resolveColor ( color ) ;
189-
190- const colors = options . colors && {
191+ let colors = options . colors && {
191192 primary_color : resolveColor ( options . colors . primaryColor ) ,
192193 secondary_color : options . colors . secondaryColor && resolveColor ( options . colors . secondaryColor ) ,
193194 tertiary_color : options . colors . tertiaryColor && resolveColor ( options . colors . tertiaryColor ) ,
194195 } ;
195196
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+
196211 const data = await this . client . rest . post ( Routes . guildRoles ( this . guild . id ) , {
197212 body : {
198213 name,
@@ -245,15 +260,28 @@ class RoleManager extends CachedManager {
245260 if ( typeof icon !== 'string' ) icon = undefined ;
246261 }
247262
248- const colors = options . colors && {
263+ let colors = options . colors && {
249264 primary_color : resolveColor ( options . colors . primaryColor ) ,
250265 secondary_color : options . colors . secondaryColor && resolveColor ( options . colors . secondaryColor ) ,
251266 tertiary_color : options . colors . tertiaryColor && resolveColor ( options . colors . tertiaryColor ) ,
252267 } ;
253268
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+
254283 const body = {
255284 name : options . name ,
256- color : options . color === undefined ? undefined : resolveColor ( options . color ) ,
257285 colors,
258286 hoist : options . hoist ,
259287 permissions : options . permissions === undefined ? undefined : new PermissionsBitField ( options . permissions ) ,
0 commit comments