mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Role hex stuff
This commit is contained in:
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;
|
||||
|
||||
Reference in New Issue
Block a user