Im getting an error of Cannot find module 'C:\Users\Michael\Desktop\Discord Bot' inside of my cmd running "node ." the full thing im getting is;
"node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module 'C:\Users\Michael\Desktop\Discord Bot'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12) at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v19.3.0"
The code i have in "main.js" is;
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '?';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ /);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
}
});
client.login('my magical token');
Inside of my commands for "ping.js" it is;
module.exports = {
name: 'ping',
description: "this is a ping command!",
execute(message, args){
message.channel.send('pong!');
}
}
Any way to fix this? do i need to start over?
I tried reinstalling everything in my node_modules and other node stuff. I should be expecting my bot to run.
CodePudding user response:
You probably want to run node main.js
not node .
.
node .
runs what is mentioned inside your package.json
as main
if thats empty it tries to run index.js
which you do not use.
CodePudding user response:
Try "node main.js". You didn't specify which file is the entry point.