title: Cannot read property "name" of undefined while "name" isn't even in the code
body: <p>This has just recently started happening, not sure if it's a bug with node or discord.js or something else, but I can't find anything that would be causing issues in my code.</p>
  
  <p>The program having issues is a program for a discord bot I made. The error only happens during one command, which sends a message to the mentioned user and stores some info in a log for later. The relevant code: </p>
  
  <pre><code>if (!rating) {
      let index = Math.floor(Math.random() * PARANOIAQUESTIONS["pg13"].length)
      message.mentions.users.first().send("Question from " + message.author.username + ": \n" + PARANOIAQUESTIONS["pg13"][index] + "\nReply with '+ans [answer]'.").catch((err) =&gt; {message.channel.send("That user has their DMs set to closed."); console.log(err)})
      paranoiaLog[message.mentions.users.first()] = message.channel
      askedQuestions[message.mentions.users.first()] = PARANOIAQUESTIONS["pg13"][index]
  } else {
      let index = Math.floor(Math.random() * PARANOIAQUESTIONS["r"].length)
      message.mentions.users.first().send("Question from " + message.author.username + ": \n" + PARANOIAQUESTIONS["r"][index] + "\nReply with '+ans [answer]'.").catch((err) =&gt; {message.channel.send("That user has their DMs set to closed."); console.log(err)})
      paranoiaLog[message.mentions.users.first()] = message.channel
      askedQuestions[message.mentions.users.first()] = PARANOIAQUESTIONS["r"][index]
  }
  </code></pre>
  
  <p>This code segment (with slight differences) is repeated many times throughout the function, different depending on the specific permissions of the server and channel the command was sent in. The error can happen in any of these repetitions, so I don't think it's a strange typo (plus it only just started happening). The strange part is this: The error message points me to 49:94, while this code is at line 1100 or so. Lines 48-52:</p>
  
  <pre><code>client.on('channelCreate', (channel) =&gt; {
      console.log("Channel created: " + channel.name + ", " + channel.id + " in " + channel.guild.name + " (" + channel.guild.systemChannelID + ")")
      serverSettingsList[channel.guild.systemChannelID][channel.id] = {"muted?": 0, "truth pg": 1, "truth pg13": 1, "truth r": 0, "dare pg": 1, "dare pg13": 1, "dare r": 0, "dare d": 1, "dare irl": 1, "wyr pg": 1, "wyr pg13": 1, "wyr r": 0, "nhie pg": 1, "nhie pg13": 1, "nhie r": 0, "paranoia pg":1, "paranoia pg13": 1, "paranoia r": 0}
      fs.writeFileSync('serversettingslist.json', JSON.stringify(serverSettingsList, null, '\t'))
  })
  </code></pre>
  
  <p>Character 94 is the l in "guild" in <code>channel.guild.name</code>. I don't know why it would be pointing me here when this code isn't even running at the time. I put <code>console.log</code>s all over the function that is running to try and see exactly what line is causing an error, but all the correct things log, <em>then</em> the error throws. On top of that, it's only caught half of the time by the <code>.catch</code> statement, so I really have no idea what it is. </p>
  
  <p>EDIT: The issue turned out to be, as others noticed, that channel.guild is not defined for DM channels. I had assumed the <code>channelCreate</code> code wouldn't be running when it messaged me, as I've had a DM open with the bot ever since I started making it, and forgot that <code>channel</code> objects are not limited to servers and apply to DMs and group DMs as well. Thanks for helping me realize my mistake!</p>