Thirteen112

Command role

Oct 1st, 2020
1,026
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.on("message", message => {
  2.   let cmd = message.content.toLowerCase().split(" ")[0];
  3.   cmd = cmd.slice(prefix.length);
  4.   if (cmd === "role") {
  5.     if (!message.channel.guild || message.author.bot) return;
  6.     let args = message.content.split(" ");
  7.     let user = message.guild.member(
  8.       message.mentions.users.first() || message.guild.members.cache.get(args[1])
  9.     );
  10.     var role = message.content
  11.       .split(" ")
  12.       .slice(2)
  13.       .join(" ")
  14.       .toLowerCase();
  15.     var role1 = message.guild.roles.cache
  16.       .filter(r => r.name.toLowerCase().indexOf(role) > -1)
  17.       .first();
  18.     if (!message.guild.member(client.user).hasPermission("MANAGE_ROLES"))
  19.       return message.channel.send(`I Need Permissions !!`);
  20.     if (!message.guild.member(message.author).hasPermission("MANAGE_ROLES"))
  21.       return;
  22.     if (!user)
  23.       return message.channel.send(
  24.         `**>>> ${prefix}role <@mention or iD> role**`
  25.       );
  26.     if (!role)
  27.       return message.channel.send(
  28.         `**>>> ${prefix}role <@mention or iD> role**`
  29.       );
  30.     if (!role1)
  31.       return message.channel.send(
  32.         `**>>> ${prefix}role <@mention or iD> role**`
  33.       );
  34.     if (user.roles.cache.find(c => c.id === role1.id))
  35.       return user.roles
  36.         .remove(role1)
  37.         .then(() => {
  38.           message.channel.send(
  39.             `**>>> Role \`${role1.name}\` removed to ${user.user}**`
  40.           );
  41.         })
  42.         .catch(err => message.channel.send("Error: **" + err.message + "**"));
  43.     user.roles
  44.       .add(role1)
  45.       .then(() => {
  46.         message.channel.send(
  47.           `**>>> Role \`${role1.name}\` added to ${user.user}**`
  48.         );
  49.       })
  50.       .catch(err => message.channel.send("Error: **" + err.message + "**"));
  51.   }
  52.   if (message.content.toLowerCase() === prefix + "help role") {
  53.     let move = new Discord.MessageEmbed()
  54.       .setTitle(`Command: role`)
  55.       .addField("Usage", `${prefix}role @user role`)
  56.       .addField("Information", "Change Roles");
  57.     message.channel.send(move);
  58.   }
  59. });
RAW Paste Data