TypeError: Cannot read property 'filter' of undefined

Discussion in 'Javascript' started by LoyRixLegendary, Jun 10, 2019.

  1. LoyRixLegendary

    LoyRixLegendary

    Joined:
    Jun 10, 2019
    Messages:
    1
    Likes Received:
    0
    I have a probleme in coding a discord bot ...

    TypeError: Can not read property 'filter' of undefined

    bot.command = new Discord.Collection ();
    fs.readdir ('./ comands /', (err, files) => { if (err) console.log (err);
    let jsFile = files.filter (f => f.split ("."). pop () === "js");
    if (jsFile.lenght <= 0) { console.log ("I can not find the command");
    return;
    }
    jsFile.forEach ((f, i) => { let props = require (`./commands / $ {f}`);
    bot.command.set (props.help.name, props);
    }); });
     
    LoyRixLegendary, Jun 10, 2019
    #1
    1. Advertisements

  2. LoyRixLegendary

    sagar.chavada

    Joined:
    Jul 12, 2019
    Messages:
    3
    Likes Received:
    0
    Location:
    Ahmedabad.
    My point of view you have to go through this one may this one help you to fix the issue.

    bot.commands = new Discord.Collection();

    fs.readdir("./commands/", (err, files) => {

    if(err) console.log(err);

    let jsfile = files.filter(f => f.split(".").pop() === "js")
    if(jsfile.length <= 0){
    console.log("Couldn't find commands.");
    return;
    }

    jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    console.log(`${f} loaded!`);
    bot.commands.set(props.help.name, props);
    });

    });
     
    sagar.chavada, Jul 19, 2019
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.