Last active
July 17, 2017 23:38
-
-
Save linuxgemini/6e69406b619639e576cb052ceef953e7 to your computer and use it in GitHub Desktop.
make your color random (discord.js 11.1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Warning: | |
The command core is written on the format of CommunityBot. | |
You can find my rendition here: | |
https://github.com/mertturunc/Bane/tree/test-dev | |
*/ | |
exports.commands = { | |
"randomcolor": { | |
process: function(bot, message) { | |
if (message.channel.type === "dm" || message.channel.type === "group") { | |
return; // discard dm and group messages | |
}; | |
if (!message.guild.member(bot.user).hasPermission("MANAGE_ROLES")) { | |
return; // check permissions for MANAGE_ROLES, if bot doesn't have it, exit | |
}; | |
if (message.guild.id !== "321037402002948099") { | |
return; // can be removable, checks if the guild is genprog | |
}; | |
if (message.member.colorRole && message.member.colorRole.members.size > 1) { | |
return; // if the color role has more than 1 user, exit | |
}; | |
var finalA = '#' + ("000000" + Math.random().toString(16).slice(2, 8).toUpperCase()).slice(-6); // generate random hex color | |
if (!message.member.colorRole) { // if user doesn't have a color role | |
var roleName = ("#" + message.author.username); // set a name variable for the new role as #<username> | |
message.guild.createRole({ // create role | |
name: roleName, // set rolename as the name variable | |
color: finalA, // set color to the random generated one | |
hoist: false, // set role to be not hoistable | |
permissions: 1177930945, // copied from genprog guild | |
mentionable: false // set role unmentionable | |
}).then(r => { // after role creation | |
message.member.addRole(r).then(gm => { // add target member to the role | |
message.channel.send("Set color to http://garden.offbeatwit.ch/color/" + finalA.replace("#", "")).catch(e => { // send user the new color (thx offbeatwitch for the site) and on error, | |
console.error("Err in command: " + e); // print error to the console | |
}); | |
}); | |
}).catch(e => { // if an error happens in role addition | |
console.error("Err in command: " + e); // print error to the console | |
}); | |
} else { // if user has a color role | |
message.member.colorRole.edit({ // edit the color role | |
color: finalA // set color to the random generated one | |
}).then(r => { // after role editing | |
message.channel.send("Set color to http://garden.offbeatwit.ch/color/" + finalA.replace("#", "")).catch(e => { // send user the new color (thx offbeatwitch for the site) and on error, | |
console.error("Err in command: " + e); // print error to the console | |
}); | |
}).catch(e => { // if an error happens in role editing | |
console.error("Err in command: " + e); // print error to the console | |
}); | |
} | |
if (message.channel.permissionsFor(message.guild.member(bot.user)).has("MANAGE_MESSAGES") && message.mentions.users.size > -1) { // if bot has MANAGE_MESSAGES permission | |
message.delete().catch(e => { // delete the incoming message and on error, | |
console.log("I don't have permissions to delete messages on Guild: " + message.guild.name + " Guild ID: " + message.guild.id); // print error to the console | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment