title: How Do I Add Roles via Discord.js?
body: <p>I'm currently creating a bot through Discord.js, and I want someone to be able to state a command in order to gain a role. However, I can't figure this out for the life of me.
  In my bot folder, I've created an addrole.js file with the following chunk of code:</p>
  <pre class="lang-js prettyprint-override"><code>const Discord = require(&quot;discord.js&quot;);
  const roles = message.guild.roles.cache.map((role) =&gt; role);
  const member = message.mentions.members.first();
  const role = message.mentions.roles.first();
  const colours = require(&quot;../colours.json&quot;);
  
  module.exports.run = async (bot, message, args) =&gt; {
    if (!message.member.hasPermission([&quot;MANAGE_ROLES&quot;, &quot;ADMINISTRATOR&quot;]))
      return message.channel.send(
        &quot;Sorry, frog lover! :disappointed: :broken_heart: You don't have permission to perform this command!&quot;
      );
  
    let rMember =
      message.mentions.members.first ||
      message.guild.members.cache.find((m) =&gt; m.user.tag === args[0]) ||
      message.guild.members;
    let role =
      message.guild.roles.cache.find((r) =&gt; r.name == args[1]) ||
      message.guild.roles.cache.find((r) =&gt; r.id == args[1]) ||
      message.mentions.roles.first();
    if (!role)
      return message.channel.send(
        &quot;Which role do I give to this user, frog lover? :point_right: :point_left:&quot;
      );
  
    if (!message.guild.me.hasPermission([&quot;MANAGE_ROLES&quot;, &quot;ADMINISTRATOR&quot;]))
      return message.channel.send(
        &quot;Sorry, friend :broken_heart: :shrug: I don't have permission to perform this command!&quot;
      );
  
    if (rMember.roles.has(role.id)) {
      return message.channel.send(
        `$rMember.displayName), already has this role!`
      );
    } else {
      await rMember.roles.add(role.id).catch((e) =&gt; console.log(e.message));
      message.channel.send(
        `The role ${role.name} has been added to ${rMember.displayName}.`
      );
    }
  
    let embed = new Discord.RichEmbed()
      .setColor(colours.redlight)
      .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
      .addField(&quot;Moderation:&quot;, &quot;Addrole&quot;)
      .addField(&quot;Mutee:&quot;, rMember.user.username)
      .addField(&quot;Reason:&quot;, reason)
      .addField(&quot;Date:&quot;, message.createdAt.toLocaleString());
  
    letsChannel = message.guild.channels.cache.find(
      (c) =&gt; c.name === &quot;beans-the-frog&quot;
    );
    sChannel.send(embedVariable);
  };
  
  module.exports.config = {
    name: &quot;addrole&quot;,
    description: &quot;Adds a role to a member of the guild!&quot;,
    usage: &quot;beans addrole&quot;,
    accessableby: &quot;Moderators&quot;,
    aliases: [&quot;ar&quot;, &quot;roleadd&quot;],
  };
  </code></pre>
  <p>I followed THIS tutorial to get here: <a href="https://www.youtube.com/watch?v=GCSbZ2UbriU" rel="nofollow noreferrer">https://www.youtube.com/watch?v=GCSbZ2UbriU</a></p>
  <p>I've given my bot the Manage_Roles permission and have attempted to state both &quot;beans addrole (role) (user)&quot; and &quot;beans addrole (user) (role)&quot;. I'm expecting him to even specify error messages, or even better yet, add the role. However, he isn't even spitting out error messages, and neither is my console. Everything else works fine, it's just that this particular function won't work. Any input/feedback would help a LOT.</p>