[SOLOVED] I have some error

so i have this code:

    const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const config = require('./config.json');
client.commands = new Discord.Collection();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setActivity("Another Chance | Type a!help")
});

fs.readdir('./cmds', (err,files) => {
    if (err) {
        console.log(err);
    }

    let cmdFiles = files.filter(f => f.split(".").pop() === "js");

    if (cmdFiles.length === 0){
        console.log("No files found");
        return;
    }

    cmdFiles.forEach((f,i) => {
        let props = require(`./cmds/${f}`);
        console.log(`${i+1}: ${f} loaded`);
        client.commands.set(props.help.name, props);
    })
})

const prefix = config.prefix;

client.on('message',msg => {
    if (msg.channel.type === "dm") return;
    if (msg.author.bot) return;
        if (msg.channel.type === "dm") return;
        if (msg.author.bot) return;
    
        let msg_array = msg.content.split(" ");
        let args1 = msg.content.slice(prefix.length).trim().split(' ');
        let args = msg_array.slice(1);
        let cmd = args1.shift().toLowerCase();
        let command = client.commands.get(cmd);
    
        if (!msg.content.startsWith(prefix)) return;
    
        if (client.commands.has(cmd)) {
            command = client.commands.get(cmd);
                if (cmd){
                    command.run(client,msg,args,args1);
                }
    }
    
});

client.login(process.env.TOKEN);

with the following errors:

    TypeError: Cannot read property 'name' of undefined

at cmdFiles.forEach (/app/discord.js:27:40)

    at Array.forEach (<anonymous>)

at fs.readdir (/app/discord.js:24:14)

    at FSReqWrap.oncomplete (fs.js:135:15)

**so i have this code:

    const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const config = require('./config.json');
client.commands = new Discord.Collection();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setActivity("Another Chance | Type a!help")
});

fs.readdir('./cmds', (err,files) => {
    if (err) {
        console.log(err);
    }

    let cmdFiles = files.filter(f => f.split(".").pop() === "js");

    if (cmdFiles.length === 0){
        console.log("No files found");
        return;
    }

    cmdFiles.forEach((f,i) => {
        let props = require(`./cmds/${f}`);
        console.log(`${i+1}: ${f} loaded`);
        client.commands.set(props.help.name, props);
    })
})

const prefix = config.prefix;

client.on('message',msg => {
    if (msg.channel.type === "dm") return;
    if (msg.author.bot) return;
        if (msg.channel.type === "dm") return;
        if (msg.author.bot) return;
    
        let msg_array = msg.content.split(" ");
        let args1 = msg.content.slice(prefix.length).trim().split(' ');
        let args = msg_array.slice(1);
        let cmd = args1.shift().toLowerCase();
        let command = client.commands.get(cmd);
    
        if (!msg.content.startsWith(prefix)) return;
    
        if (client.commands.has(cmd)) {
            command = client.commands.get(cmd);
                if (cmd){
                    command.run(client,msg,args,args1);
                }
    }
    
});

client.login(process.env.TOKEN);

with the following errors:

    TypeError: Cannot read property 'name' of undefined

at cmdFiles.forEach (/app/discord.js:27:40)

    at Array.forEach (<anonymous>)

at fs.readdir (/app/discord.js:24:14)

    at FSReqWrap.oncomplete (fs.js:135:15)

MOD EDIT: formatting

Can you invite me? It may be that you didn’t put " " around your token.

You do not need to put " " around your token when using .env

You have to put this code in every your cmd file:

exports.help = {
  name: "some-cmd-name",
  ...
}

@jarvis394, The way this is setup, that is not needed, its only needed when the code has that configuration in it and will be used.

@Callum-OKane, well,

 client.commands.set(props.help.name ...

This line should get props, otherwise it throws an error of getting some properties from undefined. Also, there is no props checking, maybe,

props.help && client.commands.set( ...

would help.

Oh right sorry, must have missed that.