Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
¿Por qué index.bindClient no es una función?

¿Por qué esto no es una función? Importar ./src/index.js en ./index.js funciona bien, pero tratar de importarlo en ./src/Client.js simplemente no me deja. No es una "ruta de archivo no válida" porque no tengo ningún error y se completó automáticamente en la función require .

Aquí está mi código:

./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) } }) ); } }

Este no es mi código completo, solo incluí las partes importantes relacionadas con el error. Intenté iniciar sesión tanto como pude y todo, excepto el index en ./src/Client.js , era lo que se suponía que era. Este error incluso ocurrió cuando traté de configurarlo como module.exports.bindClient = ...

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Como dijo @Elitezen en su comentario , los archivos se requerían entre sí. Poner el require en la parte inferior y llamar a la función directamente desde allí funcionó

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

0

Puedes desestructurarlo...

 const { Send, MessageDelete, Command, Client, bindClient } = require("./src/index.js")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!