title: How to find a User ID from a Username in Discord.js?
body: <p>I have a json file (localJSON.json) with Discord usernames (i.e. JohnDoe#1234) and need to get the User IDs from these usernames in order to have a role added. Every place I have looked online has resulted with either an 'undefined' or 'null' value for rMember. Verified that the code to add a role works when given a User ID as a string, but can't find how to get a User ID from a username. 
  How do I get a user's ID from their Username using Discord.js?</p>
  
  <pre><code>localJSON.json
  [
    {
      "discordName": "JohnDoe#1234"
    },
    {
      "discordName": "MarySue#5678"
    }
  ]
  </code></pre>
  
  <pre><code>function addRole(discordUsername, gameName, message){
    var roleName = "";
    //Switch statement to assign roleName to a valid guild role based on argument
  
    var userID = discordUsername.id; //Pseudo code, Need to accomplish this
  
    var rMember = message.guild.members.get(userID); //Needs UserID as string
    var gRole = message.guild.roles.find((role) =&gt; role.name == roleName); 
    if (!rMember) { //if member not in server
      message.channel.send(rMember + " is not in the server!");
    } else { //assign role
      rMember.addRole(gRole);
    }
  }
  
  async run(message, args){
    ...
    for (var i = 0; i &lt; localJSON.length; i++) {
       var currentEntry = localJSON[i];
       var currrentUserName = currentEntry.discordName;
       addRole(currrentUserName, args, message); //addRole(discordUsername, gameName, message);
    }
  }
  </code></pre>