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

103
Visualizações
Why is index.bindClient is not a function?

Why is this not a function? Importing ./src/index.js in ./index.js works just fine, but trying to import it in ./src/Client.js just doesn't let me. It's not some "invalid file path" because I don't have any errors, and it autofilled in the require function.

Here is my code:

./index.js

const index = require("./src/index.js")
console.log(index) //logs the module

./src/Client.js

const index = require("./index.js") //I even tried require("../src/index.js") and the full path (D:/...)
console.log(index) //logs empty object

index.bindClient(client) //TypeError: index.bindClient is not a function

./src/index.js

module.exports = {
    Send,
    MessageDelete,
    Command,
    Client: C,
/**
 * 
 * @param {Client} client
 */
    bindClient(client) {
        c = client;
        return (
            c.on("messageCreate", msg => {
            const command = commands.find(c => msg.content.startsWith(c.name))
            if (command) {
                command.send ? Send(command.send, msg.channel) : null
                command.delete ? MessageDelete(msg) : null
                command.emit("execute", msg, command)
            }
        })
        );
    }
}

This is not my full code, I only included the important parts that relate to the error. I tried logging as much as I could and everything except for index in ./src/Client.js was what it was supposed to be. This error even happened when I tried to set it like module.exports.bindClient = ...

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As said by @Elitezen in their comment, the files were requiring each other. Putting the require at the bottom and calling the function directly from it worked

require("./index.js").bindClient(client)
about 4 years ago · Juan Pablo Isaza Relatório

0

You can destructure it...

const { Send, MessageDelete, Command, Client, bindClient } = require("./src/index.js")
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