English 中文(简体)
Discord.js not recognizing file path as directory
原标题:
  • 时间:2023-05-27 03:02:57
  •  标签:
  • discord.js

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

问题回答

暂无回答




相关问题
How can I make my bot works in multiple servers?

I know that this question has been asked for discord.py, but couldn t find a discord.js one Currently I m working on a small Discord Bot, and I would like to make it with possible that it can be used ...

Discord.js not recognizing file path as directory

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 This is with the ...

Discord bot responds multiple times for one event

I want my bot to respond once to a command such as .on. However, it responds multiple times per input: The code is: client.on( message , message =>{ if(message.content === .on ){ ...

热门标签