-1

Please help me
the text of the error I get in the terminal:

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

TypeError: Cannot read properties of undefined (reading 'readdir') at Object. (C:\Users\tDiff\Desktop\TDIFF\tdıff.js:15:4) enter code here

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MEMBERS
    ]
})
const {token} = require("./ayarlar.json")
const {fs} = require("fs");
const { Options } = require("discord.js");
global.client = client;
client.commands = (global.commands = []);

fs.readdir("./komutlar/",(err,files) => {   // where l got the error
    if(err) throw err;  

        files.forEach(f => {
        if(!f.endsWith(".js")) return;
        let p = require(`./komutlar/${f}`)
        
        client.commands.push({
            name:p.name.toLowerCase(),
            description:p.description,
            options:p.options,
            type:p.type,
        });
        console.log(`✔ Komut eklendi: ${p.name}`);
    })
});

fs.readdir("./events/",(err,files) => {  // where l got the error
    files.forEach(f => {
        if(!f.endsWith(".js"))return;
        const e = require(`./events${f}`);
        let eName = f.split(".")[0];
        
        client.on(eName, (...args) => {
            e()
        })
    })
});


client.once("ready",() => {
    console.log(`${client.user.tag} Aktif!`);
    client.user.setPresence({
        activities:[
            {
                name:"TDIFF",
                type:"LISTENING"
            }
        ],
        status:"dnd"
    })
})
client.login(token)```

Progman
  • 16,827
  • 6
  • 33
  • 48
tDiff
  • 1
  • 1
  • 3

1 Answers1

0

The error you are getting is actually telling you that you are trying to read/call someting (in your case readdir) on an object/class/... which is undefined.

in your case fs is undefined and the interpreter is trying execute this:

undefined.readdir(...)

which does not make any sense since undefined does not have any properties on its own.

I would assume that you forgot to import the fs package on top of the file:

const fs = require('fs');
metodribic
  • 1,561
  • 17
  • 27
  • I'm not sure what you meant with your comment? `fs` is a file system module which needs to be imported in a file to use it and that is the standard practice in node. Please check [official documentation](https://nodejs.org/api/fs.html) for further clarification. – metodribic May 17 '22 at 20:50