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

99
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

You can destructure it...

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