title: Discord.js - TypeError: Cannot read properties of undefined (reading 'set')
body: <p>This is in main.js:</p>
  <pre><code>const { Client, Intents, DiscordAPIError } = require('discord.js');
  
  const Discord = require('discord.js');
  
  const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
  
  const prefix = 'js!';
  
  const fs = require('fs');
  
  client.command = new Discord.Collection();
  
  fs.readdir(&quot;./commands/&quot;, (err, files) =&gt; {
      if(err) console.error(error)
      let jsfiles = files.filter(f =&gt; f.split(&quot;.&quot;).pop() === &quot;js&quot;)
      if (jsfiles.length &lt;= 0) {
        return console.log(&quot;No commands to log in FOLDER NAME&quot;)
      }
      console.log(`Loading ${jsfiles.length} commands from FOLDER NAME...`)
      jsfiles.forEach((f,i) =&gt; {
        let props = require(`./commands/${f}`)
        console.log(`${i + 1}: ${f} loaded!`)
        client.commands.set(f, props)
      })
    });
  
  client.once('ready',() =&gt; {
      console.log('bot is on')
  });
  
  client.on('message', message =&gt;{
      if(!message.content.startsWith(prefix) || message.author.bot) return;
      const args = message.content.slice(prefix.length).split(/ +/);
      const command = args.shift().toLowerCase();
  
      if(command === 'ping'){
          let cmd = client.commands.get(command+&quot;.js&quot;)
              if (cmd) cmd.run(bot, message, args, prefix)
      } 
  });
  
  client.login('Prefix')
  </code></pre>
  <p>And this is in ping.js:</p>
  <pre><code>const { Client, Intents, DiscordAPIError } = require('discord.js');
  
  const Discord = require('discord.js')
  
  const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
  
  module.exports.run = async (client, message, args, prefix) =&gt; {
      var ping = Date.now() - message.createdTimestamp + &quot; ms&quot;;
  
      message.channel.send('Ma ping is' + ` ${Date.now() - message.createdTimestamp}` + 'ms')
  };
  module.exports.help = {
    name: &quot;ping&quot;,
    usage: &quot;Ping Command&quot;,
  };
  </code></pre>
  <p>But if I run main.js with the command <code>node .</code> in terminal, I get this error:</p>
  <pre><code>Loading 1 commands from FOLDER NAME...
  1: ping.js loaded!
  /home/ender/Desktop/Projects &amp; Stuff/Coding/Discord Bot (JS)/main.js:23
        client.commands.set(f, props)
                        ^
  
  TypeError: Cannot read properties of undefined (reading 'set')
      at /home/ender/Desktop/Projects &amp; Stuff/Coding/Discord Bot (JS)/main.js:23:23
      at Array.forEach (&lt;anonymous&gt;)
      at /home/ender/Desktop/Projects &amp; Stuff/Coding/Discord Bot (JS)/main.js:20:13
      at FSReqCallback.oncomplete (node:fs:188:23)
  </code></pre>
  <p>I use linux as my main os and the version of node.js I use is v16.11.1 and npm version is 8.0.0!</p>
  <p>Please help, I started recently to use discord.js after I realized that discord.py was dead and I need help!</p>
  <p><strong>Edit One</strong>
  This is how my files are organized: <a href="https://i.stack.imgur.com/9Wuqf.png" rel="nofollow noreferrer">picture 1</a></p>