title: TypeError: Cannot read property 'users' of undefined using Discordjs v12 [SOLVED]
body: <p>I'm working on a JavaScript Discord(v12.4.0) bot and I'm trying to create a channelinfo command but I have an error when defining and finding the propierties of message.channel.</p>
  <p>This is the <strong>channelinfo.js</strong></p>
  <pre><code>const { MessageEmbed } = require(&quot;discord.js&quot;)
  
  module.exports = {
    name: &quot;channelinfo&quot;,
    cooldown: 5,
    aliases: [&quot;ci&quot;, &quot;infochannel&quot;],
    description: &quot;Displays info about a channel!&quot;,
    guildOnly: true,
    execute(client, message, args) {
    
    const Discord = require(&quot;discord.js&quot;)
  
  //Definimos discord.
  
  // const channel = message.mentions.channels.first() || message.guild.channels.cache.find(x =&gt; x.id == args[0])
  
  //Definimos el canal del cual sacaremos informacion. Obteniendo el primer canal mencionado o la primera id.
      
  //if (!channel) return message.reply(&quot;You must enter a channel!&quot;)
  //Si  no menciono un canal o no puso una id, retorna.
  
  
  //Definimos el embed que enviaremos
   const cha = new Discord.MessageEmbed()
      
     .addField(`Name:`, `- ${Discord.Util.escapeMarkdown(message.channel.name)}`)
  
  //Obtenemos el nombre del canal.
  
      .addField(`Mention:`, `- \`${message.channel}\``)
  
  //Un simple ejemplo de como se menciona este.
  
      .addField(`ID:`, `- ${message.channel.id}`)
  
  //Se obtiene la id del canal.
  
      .addField(`Type`, `- ${message.channel.type}`)
  
  //Obtenemos el tipo de canal, noticias, texto, voz etc
      
       .addField(`Is it nsfw?`, `${message.channel.nsfw}`)
  
  //Revisamos si el canal es nswf, mediante un boolean (false | true)
  
      .addField(`Topic:`, `- ${message.channel.topic.toString().length &lt; 1 ? &quot;There's no topic&quot; : message.channel.topic}`)
  
  //Se obtiene el tema del canal, si el contenido es menor a 1 caracter (Se hace esto por que a veces se buguean los temas) retorne a &quot;No hay un tema.&quot;
  //Si hay un tema, lo envia.
     
      .addField(`Category:`, `- ${message.channel.parent.name}`)
   
  //Obtenemos la categoria en el que esta el canal.
      
      .setColor(&quot;RANDOM&quot;) //Color(?
      
      message.channel.send(cha)
  
  }}
  </code></pre>
  <p>And this is the <strong>console log error</strong></p>
  <pre><code>2020-10-26T13:29:59.413677+00:00 app[worker.1]:     TypeError: Cannot read property 'channel' of undefined
  2020-10-26T13:29:59.413677+00:00 app[worker.1]:     at Object.execute (/app/commands/channelinfo.js:26:72)
  </code></pre>
  <p>At first, I tryed adding a const that will get the channel with mention or with the ID. The code was this one:</p>
  <pre><code>const channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0]) || message.channel;
  </code></pre>
  <p>As it didn't work, I tryed only defining channel as message.channel (const channel = message.channel) but i had the same error.</p>
  <p>Then I erased the const line and I used <code>message.channel</code> instead of <code>channel</code> at the embed files but I still get the same error.</p>
  <p>I am sure that it isn't an error caused for the command handler because all the other commands are working fine.</p>
  <p>Curiosity: I tryed making a similar command but displaying info about a role and the error was the same(TypeError: Cannot read property 'roles' of undefined)</p>
  <p>Here's the <strong>bot.js</strong></p>
  <pre><code>// require fs para el command handler
  const fs = require('fs'); 
  // require the discord.js module
  const Discord = require('discord.js');
  
         const { token, prefix, yt_api_key } = require('./config.json');
  // create a new Discord client
  const client = new Discord.Client();
  
  
        
  fs.readdir(&quot;./events/&quot;, (err, files) =&gt; {
    if (err) return console.error(err);
    files.forEach(file =&gt; {
      const event = require(`./events/${file}`);
      let eventName = file.split(&quot;.&quot;)[0];
      client.on(eventName, event.bind(null, client));
    });
  });
  
  
  client.noprefixcommands = new Discord.Collection();
  
  fs.readdir(&quot;./noprefixcommands/&quot;, (err, files) =&gt; {
    if (err) return console.error(err);
    files.forEach(file =&gt; {
      if (!file.endsWith(&quot;.js&quot;)) return;
      let props = require(`./noprefixcommands/${file}`);
      let noprefixcommandName = file.split(&quot;.&quot;)[0];
      client.noprefixcommands.set(noprefixcommandName, props);
    });
  });
  
  
  
  client.commands = new Discord.Collection();
  
  const cooldowns = new Discord.Collection();
  
  
  const commandFiles = fs.readdirSync('./commands').filter(file =&gt; file.endsWith('.js'));
  
  for (const file of commandFiles) {
      const command = require(`./commands/${file}`);
      client.commands.set(command.name, command);
  }
  
  
  
  client.on('message', message =&gt; {
      if (!message.content.startsWith(prefix) || message.author.bot) return;
  
      const args = message.content.slice(prefix.length).trim().split(/ +/);
      const commandName = args.shift().toLowerCase();
  
      const command = client.commands.get(commandName)
          || client.commands.find(cmd =&gt; cmd.aliases &amp;&amp; cmd.aliases.includes(commandName));
  
      if (!command) return;
      
      if (command.guildOnly &amp;&amp; message.channel.type === 'dm') {
      return message.reply('I can\'t execute that command inside DMs!');
  }
      
            if (command.args &amp;&amp; !args.length) {
              let reply = `You didn't provide any arguments, ${message.author}!`;
  
          if (command.usage) {
              reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
          }
  
          return message.channel.send(reply);
      }
  
         if (!cooldowns.has(command.name)) {
          cooldowns.set(command.name, new Discord.Collection());
      }
      const now = Date.now();
      const timestamps = cooldowns.get(command.name);
      const cooldownAmount = (command.cooldown || 3) * 1000;
      if (timestamps.has(message.author.id)) {
          const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
          if (now &lt; expirationTime) {
              const timeLeft = (expirationTime - now) / 1000;
              return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before using the \`${command.name}\` command.`);
          }
      }
      timestamps.set(message.author.id, now);
      setTimeout(() =&gt; timestamps.delete(message.author.id), cooldownAmount);
      
  try {
      command.execute(message, args);
  } catch (error) {
      console.error(error);
      message.reply('there was an error trying to execute that command!');
  }
  });
  
  
  client.login(process.env.BOT_TOKEN);
  </code></pre>
  <p>I use Github for editing the code and Heroku for hosting.</p>
  <p>I started having that issue when I started building the command at Glitch but I returned to Github and the issue was like the Glitch one.</p>
  <p>Please someone help
  I would be very greateful</p>