I am currently coding a Discord bot in JS with Node.js and I wanted to write the commands code in a file for each command. All of these files are in a commands folder. Here is my code : in index.js :
const help = require("./commands/help.js")
help.help()
and in help.js :
function help() {
const embed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("Commandes du serveur")
.addField("&help", "Commandes du bot")
.addField("&youtube", "Lien vers la chaîne YouTube d'ANGI49")
.addField("&twitch", "Lien vers la chaîne Twitch d'ANGI49")
.setFooter("Bot développé par ANGI498045 et ywalt.js")
message.reply({ embeds: [embed]});
}
module.exports()
The import never works and i have a module not found error Thanks
For a CommonJS module that uses require() (there two different module types in nodejs), in help.js, change this:
module.exports()
to this:
module.exports.help = help;
Then, you should be able to do this:
const help = require("./commands/help.js")
help.help()
As long as the "./commands/help.js" path is correct.