Home > Software design >  discord.js Error: ENOENT: no such file or directory, scandir './commands'
discord.js Error: ENOENT: no such file or directory, scandir './commands'

Time:10-17

I am trying to make this work, but it keeps saying that my directory for the folder is wrong, when it is correct. I had help from another who couldn't solve this. Can anyone help?

Code:

const { Client, Intents, Collection } = require('discord.js')
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')
const Discord = require('discord.js')

const fs = require('fs')
const intents = new Discord.Intents(32767);
const client = new Discord.Client({ intents });

const config = require('./Data/config.json')

const versionNumber = "V1.0.0"

client.once("ready", () => {
    console.log('-------------------------------------------');
    console.log(`| Successfully logged in as Logic RP#7590 |`);
    console.log('-------------------------------------------');

    const commands = []
    const commands_information = new Collection();
    const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"))

    for (const file of commandFiles) {
        const command = require(`./commands/${file}`)
        console.log(`Command loaded: ${command.data.name}`)
        commands.push(command.data.toJSON())
        commands_information.set(command.data.name, command);
    }

    const rest = new REST({ version: '9' }).setToken(config.token);

    (async () => {
        try {
            console.log('Started refreshing application (/) commands.');
            await rest.put(
                Routes.applicationGuildCommands(config.botConfiguration.client, config.botConfiguration.guild),
                { body: commands },
            );
            console.log('Successfully reloaded application (/) commands.');
        } catch (error) {
            console.error(error);
        }
    })();

    client.on('interactionCreate', async interaction => {
        if (!interaction.isCommand()) return;

        const { commandName } = interaction;

        if (!commands_information.has(commandName)) return;

        try {
            await commands_information.get(commandName).execute(client, interaction, config);
        } catch (error) {
            console.error(error);
            await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
        }
    })
})

client.on("guildMemberAdd", async (member) => {
    let members = client.guilds.cache.reduce((a, g) => a   g.memberCount, 0);
    console.log(`${member.user.tag} has joined Logic RP`);
    console.log('-------------------------------------------');
    const embed = new Discord.MessageEmbed()
        .setTitle(`Welcome to the ${member.guild.name} Discord server!`)
        .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
        .setColor('GREEN')
        .addFields(
            { 
                name: "✅ Have fun!",
                value: "The most important thing for us is that YOU have fun! You can chat with others in <#898349995315576883> and have all the fun that you want or talk to the community.", 
                inline: false 
            },
            { 
                name: "           
  • Related