mirror of
https://github.com/danbulant/discord.js
synced 2026-09-18 05:54:20 +00:00
Role hex stuff
This commit is contained in:
parent
f2708dd26f
commit
50c6fa3433
3 changed files with 20 additions and 3 deletions
File diff suppressed because one or more lines are too long
|
|
@ -354,6 +354,10 @@ class RESTMethods {
|
|||
data.position = _data.position || role.position;
|
||||
data.color = _data.color || role.color;
|
||||
|
||||
if (data.color.startsWith('#')) {
|
||||
data.color = parseInt(data.color.replace('#', ''), 16);
|
||||
}
|
||||
|
||||
if (typeof _data.hoist !== 'undefined') {
|
||||
data.hoist = _data.hoist;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -114,11 +114,11 @@ class Role {
|
|||
|
||||
/**
|
||||
* Set a new color for the role
|
||||
* @param {Number} color the new color for the role
|
||||
* @param {Number|String} color the new color for the role, either a hex string or a base 10 number
|
||||
* @returns {Promise<Role, Error>}
|
||||
* @example
|
||||
* // set the color of a role
|
||||
* role.setColor(parseInt('FF0000', 16))
|
||||
* role.setColor('#FF0000')
|
||||
* .then(r => console.log(`Set color of role ${r}`))
|
||||
* .catch(console.log);
|
||||
*/
|
||||
|
|
@ -222,6 +222,19 @@ class Role {
|
|||
toString() {
|
||||
return `<@&${this.id}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hexadecimal version of the role color, with a leading hashtag.
|
||||
* @type {String}
|
||||
* @readonly
|
||||
*/
|
||||
get hexColor() {
|
||||
let col = (this.color).toString(16);
|
||||
while (col.length < 6) {
|
||||
col = `0${col}`;
|
||||
}
|
||||
return `#${col}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Role;
|
||||
|
|
|
|||
Loading…
Reference in a new issue