Search code examples
node.jsnpmdiscord.js

Error: ENOENT: no such file or directory, stat discord.js


I'm trying to run a bot via Visual Studio Code, my bot works fine for a couple of minutes before completely breaking with an error that idk how to fix.

My Code:

const { Client, GatewayIntentBits} = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const TOKEN = ':P';
setInterval(function () {
    var User = [
        "User1",
        "User2"
    ]


    client.on('ready', client => {
        const someFunc = () => {
            var randomUser = User[Math.floor(Math.random() * User.length)];
            var randomUser2 = User[Math.floor(Math.random() * User.length)];
            var randomUser3 = User[Math.floor(Math.random() * User.length)];
            var randomUser4 = User[Math.floor(Math.random() * User.length)];

            var Action = [
                { content: (randomUser) + " rembered 😀", files: [{ attachment: "./Image/" + (randomUser) + ".png" }] },
                { content: (randomUser) + " forgor 💀", files: [{ attachment: "./Image/" + (randomUser) + ".png" }] }


            ]

            client.channels.cache.get('1246634621874213007').send(Action[Math.floor(Math.random() * Action.length)]);

            setTimeout(someFunc, 60000);
        }
        setTimeout(someFunc, 60000); 
    }),
    client.login(TOKEN) 
}, 60000);

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`)
})

The Error:

node:internal/fs/promises:1026
    binding.stat(pathModule.toNamespacedPath(path),
            ^

Error: ENOENT: no such file or directory, stat
    at Object.stat (node:internal/fs/promises:1026:13)
    at DataResolver.resolveFile (J:\Desktop\Folder\R&R Anything 2.0\node_modules\discord.js\src\util\DataResolver.js:131:30)
    at MessagePayload.resolveFile (J:\Desktop\Folder\R&R Anything 2.0\node_modules\discord.js\src\structures\MessagePayload.js:261:54)
    at J:\Desktop\Folder\R&R Anything 2.0\node_modules\discord.js\src\structures\MessagePayload.js:225:85
    at Array.map (<anonymous>)
    at MessagePayload.resolveFiles (J:\Desktop\Folder\R&R Anything 2.0\node_modules\discord.js\src\structures\MessagePayload.js:225:56)
    at TextChannel.send (J:\Desktop\Folder\R&R Anything 2.0\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:50)
    at Timeout.someFunc [as _onTimeout] (J:\Desktop\Folder\R&R Anything 2.0\index.js:136:62)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'stat'
}

It worked as expected for about 4-5 minutes before throwing an error I don't understand.


Solution

  • After further research I found out this error was related to the version of node I was using, this problem no longer occurs after updating.