From a10c453ecf2e0263449c06e804986ffd86f6da5c Mon Sep 17 00:00:00 2001 From: loicbersier Date: Thu, 30 Jan 2020 17:50:31 +0100 Subject: [PATCH] Set your rank to a color of your choice --- commands/utility/color.js | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 commands/utility/color.js diff --git a/commands/utility/color.js b/commands/utility/color.js new file mode 100644 index 00000000..26b661cd --- /dev/null +++ b/commands/utility/color.js @@ -0,0 +1,79 @@ +const { Command } = require('discord-akairo'); + +class colorCommand extends Command { + constructor() { + super('color', { + aliases: ['color', 'colour'], + category: 'utility', + clientPermissions: ['SEND_MESSAGES', 'MANAGE_ROLES'], + args: [ + { + id: 'color', + type: 'string' + } + ], + description: { + content: 'Set your rank to a specified hex value OR (ColorResolvable)[https://discord.js.org/#/docs/main/master/typedef/ColorResolvable]', + usage: '[hex color OR ColorResolvable]', + examples: ['#FF0000', 'WHITE'] + } + }); + } + + async exec(message, args) { + let ColorResolvable = [ + 'default', + 'white', + 'aqua', + 'green', + 'blue', + 'yellow', + 'purple', + 'luminous_vivid_pink', + 'gold', + 'orange', + 'red', + 'grey', + 'darker_grey', + 'navy', + 'dark_aqua', + 'dark_green', + 'dark_blue', + 'dark_purple', + 'dark_vivid_pink', + 'dark_gold', + 'dark_orange', + 'dark_red', + 'dark_grey', + 'light_grey', + 'dark_navy' + ]; + + if (args.color.match(/^#[0-9A-F]{6}$/i) || ColorResolvable.includes(args.color.toLowerCase())) { + let role = message.guild.roles.find(role => role.name === args.color); + if (!role) { + message.guild.roles.create({ + data: { + name: args.color, + color: args.color.toUpperCase(), + permissions: 0 + }, + reason: 'Color command' + }); + return message.channel.send('Role created! try again to apply it to yourself!'); + } else if (message.guild.member(message.author).roles.has(role.id)) { + message.guild.member(message.author).roles.remove(role); + return message.channel.send('Role removed!'); + } + /* For some reason this doesn't work. + role = message.guild.roles.find(role => role.name === args.color); + */ + message.guild.member(message.author).roles.add(role); + return message.channel.send('Role added!'); + } else { + return message.channel.send(`${args.color} is not a valide color`); + } + } +} + +module.exports = colorCommand; \ No newline at end of file