Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda