Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
How to import a function in javascript?

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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda