Hello I am creating a Discord Bot on my MAC with Big Sur 11.0.1 and am having problems with my JavaScript Code can someone please help me?
I installed Node.js and Discord.js
I used NPM Init to create the json files in the correct folder
When I attempt to execute the code I continue to get this error
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module '/Users/ufreewoody/desktop/MyDiscordBot/commands/${file}'
Require stack:
at Function.Module.load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/ufreewoody/Desktop/MyDiscordBot/main.js:13:21)
at Module.compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module.extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module.load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/runmain:76:12) {
code: 'MODULENOTFOUND',
requireStack: [ '/Users/ufreewoody/Desktop/MyDiscordBot/main.js' ]
}
I have attempted to edit the $Path variable using the
Sudo nano /etc/paths
command and I tried to specify the absolute path to the main.js file with
/Users/ufreewoody/Desktop/MyDiscordBot folder
this is where this file is located but it is still not working.
What am I doing wrong with my code or what can I do to specify the absolute path to the folder and file.
I installed Node.js and Discord.js
I used NPM Init to create the json files in the correct folder
When I attempt to execute the code I continue to get this error
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module '/Users/ufreewoody/desktop/MyDiscordBot/commands/${file}'
Require stack:
/Users/ufreewoody/Desktop/MyDiscordBot/main.js
at Function.Module.load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/ufreewoody/Desktop/MyDiscordBot/main.js:13:21)
at Module.compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module.extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module.load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/runmain:76:12) {
code: 'MODULENOTFOUND',
requireStack: [ '/Users/ufreewoody/Desktop/MyDiscordBot/main.js' ]
}
I have attempted to edit the $Path variable using the
Sudo nano /etc/paths
command and I tried to specify the absolute path to the main.js file with
/Users/ufreewoody/Desktop/MyDiscordBot folder
this is where this file is located but it is still not working.
What am I doing wrong with my code or what can I do to specify the absolute path to the folder and file.
Code Block 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('/Users/ufreewoody/desktop/MyDiscordBot/commands').filter(file => file.endsWith('.js')); for(const file of commandFiles){ const command = require('/Users/ufreewoody/desktop/MyDiscordBot/commands/${file}'); client.commands.set(command.name.command); } client.once('ready',() => { console.log('Walter 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); } else if (command == 'youtube'){ client.commands.get('youtube').execute(message, args); } else if (command == 'Strawberry'){ message.channel.send('Im fluttering for your Love Strawberry Light Blue Butterfly'); } else if (command == ('Light Blue Butterfly')){ message.command.send('Sugie StrawBerry'); } }); client.login('NzgwNTA1ODM1NDk0MTc4ODE2.X7wEtA.fy9ssTMv4P7LJFZ26MXGFyNrSGs');