I am trying to learn how to use the / command system in Discord.js, however, following the Discord.js guide results in the following error:
Error: ENOTDIR: not a directory, scandir
on line:
deploy-commands.js:14:26
(this is the const commandFiles line)
This is with the code directly from the guide site:
const commands = [];
// Grab all the command files from the commands directory you created earlier
const foldersPath = path.join(__dirname, commands );
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith( .js ));
// Grab the SlashCommandBuilder#toJSON() output of each command s data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ( data in command && execute in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
I have tried altering the code in a few ways, some of which allow me to launch the bot, but it does not execute the / commands when they are used.
My bot will display the command, but when I use the / command, the bot will not actually run my command file.
guide site: text