Skip to content

Instantly share code, notes, and snippets.

@Cleanse
Last active February 22, 2016 03:07
Show Gist options
  • Save Cleanse/f545a6b8e3fbc6d32eda to your computer and use it in GitHub Desktop.
Save Cleanse/f545a6b8e3fbc6d32eda to your computer and use it in GitHub Desktop.
role color change
bot.on('message', function(message)
{
if (message.content.indexOf("!color") === 0) {
//check if the message length is satisfactory
if (message.content.split(" ").length === 3) {
var colorDecimal = message.content.split(" ")[2];
if (message.channel.server.roles.get("name", message.content.split(" ")[1])) {
var role = message.channel.server.roles.get("name", message.content.split(" ")[1]);
} else {
bot.reply(message, "The role you entered ("+ message.content.split(" ")[1] +") does not exist.");
return false;
}
if (message.channel.server.roles.get("name", "RoleColourAdmin")) {
var permittedRole = message.channel.server.roles.get("name", "RoleColourAdmin");
} else {
bot.reply(message, "You need to be a member if the 'RoleColourAdmin' role or it does not exist.");
return false;
}
var member = message.sender;
if (typeof role !== "undefined") {
if (member.hasRole(permittedRole)) {
bot.updateRole(role, {
color: colorDecimal
}).then(function (role) {
// this executes if the change was successful
bot.reply(message, "done! using the color " + role.color);
}).catch(function (e) {
console.log(e);
// this executes if it wasn't successful
bot.reply(message, "an error occurred. Was that a valid dec color? (Colors: https://www.mathsisfun.com/hexadecimal-decimal-colors.html)");
});
} else {
bot.reply(message, "Sorry, ask an admin if you want a unique color.");
}
}
} else {
bot.reply(message, "Correct usage: `!color RoleName color_decimal_value` (Colors: https://www.mathsisfun.com/hexadecimal-decimal-colors.html)");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment