error

I have done codes of basic slash commands, but when i try to run node deploy-commands.js, this error appears: Error: ENOTDIR: not a directory, scandir 'C:\Users\fanmo\OneDrive\Plocha\taubine\commands\ping.js' at Object.readdirSync (node:fs:1527:3) at Object.<anonymous> (C:\Users\fanmo\OneDrive\Plocha\taubine\deploy-commands.js:14:26)
at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { errno: -4052, syscall: 'scandir', code: 'ENOTDIR', path: 'C:\Users\fanmo\OneDrive\Plocha\taubine\commands\ping.js' }
40 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
average monarchist fan
Node.js v18.17.1
treble/luna
treble/luna10mo ago
you're scanning a file as directory, or the directory doesnt exist
average monarchist fan
so how to fix it
treble/luna
treble/luna10mo ago
fix your file structure or fix your file scanning
treble/luna
treble/luna10mo ago
your code expects your commands to be in a subfolder probably
average monarchist fan
well i can execute commands not but "The application did not respond"
treble/luna
treble/luna10mo ago
do you listen for the interactionCreate event
average monarchist fan
wdym (sry im really amateur)
treble/luna
treble/luna10mo ago
show your index.js file
average monarchist fan
const fs = require('node:fs'); const path = require('node:path'); const { Client, Collection, Events, GatewayIntentBits } = require('discord.js'); const { token } = require('./config.json'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.commands = new Collection(); const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log([WARNING] The command at ${filePath} is missing a required "data" or "execute" property.); } } } client.once(Events.ClientReady, () => { console.log('Ready!'); }); client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); } else { await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } } }); client.login(token);
treble/luna
treble/luna10mo ago
and do you get any output? is your client ready and online
average monarchist fan
bot is online
treble/luna
treble/luna10mo ago
log your command variable right before your if(!command) statement
average monarchist fan
my index.js looks like that rn: const fs = require('node:fs'); const path = require('node:path'); const { Client, Collection, GatewayIntentBits } = require('discord.js'); const { token } = require('./config.json'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.commands = new Collection(); const foldersPath = path.join(dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log([WARNING] The command at ${filePath} is missing a required "data" or "execute" property.); } } } const eventsPath = path.join(dirname, 'events'); const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); for (const file of eventFiles) { const filePath = path.join(eventsPath, file); const event = require(filePath); if (event.once) { client.once(event.name, (...args) => event.execute(...args)); } else { client.on(event.name, (...args) => event.execute(...args)); } } client.login(token);
treble/luna
treble/luna10mo ago
and do you have an events folder
average monarchist fan
y interactionCreate.js and ready.js
d.js docs
d.js docs10mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
average monarchist fan
I give up ig
treble/luna
treble/luna10mo ago
do what i said and show your interactionCreate file
average monarchist fan
const { Events } = require('discord.js'); module.exports = { name: Events.ClientReady, once: true, execute(client) { console.log(Ready! Logged in as ${client.user.tag}); }, };
treble/luna
treble/luna10mo ago
thats not your interactionCreate
average monarchist fan
const { Events } = require('discord.js'); module.exports = { name: Events.InteractionCreate, async execute(interaction) { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); if (!command) { console.error(No command matching ${interaction.commandName} was found.); return; } try { await command.execute(interaction); } catch (error) { console.error(Error executing ${interaction.commandName}); console.error(error); } }, };
treble/luna
treble/luna10mo ago
log your command variable
average monarchist fan
I'm back client.on('interactionCreate', async (interaction) => { // Your existing code here // Logging the 'command' variable console.log(command); // Rest of your code here }); ?
treble/luna
treble/luna9mo ago
basically assuming you actually kept your previous code
average monarchist fan
well it's the same
treble/luna
treble/luna9mo ago
and what does it log
average monarchist fan
now this pops-up: Error: Cannot find module '../config.json' Require stack: - C:\Users\fanmo\OneDrive\Plocha\taubine\index.js at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15) at Module._load (node:internal/modules/cjs/loader:922:27) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:121:18) at Object.<anonymous> (C:\Users\fanmo\OneDrive\Plocha\taubine\index.js:4:19) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\Users\fanmo\OneDrive\Plocha\taubine\index.js' ] } Node.js v18.17.1
treble/luna
treble/luna9mo ago
you didn't create a config.json then
average monarchist fan
but I have when i returned to the project, i didnt change anything from that uh i just give up ig
treble/luna
treble/luna9mo ago
also, there's a difference between ./ and ../
average monarchist fan
.. you can clearly see
treble/luna
treble/luna9mo ago
well there's your issue its ./
treble/luna
treble/luna9mo ago
../ is not ./ its rather basic js to know the difference
average monarchist fan
nvm also, how did you even find out from image
treble/luna
treble/luna9mo ago
because your stack shows you used ../