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

163
Views
¿Cómo puedo llamar a las funciones de Discord.js desde un archivo lib.js a index.js?

Estoy tratando de tener una clase separada llena de mis funciones para que index.js no se desordene. El problema que encontré es que mi nuevo archivo lib.js no puede funcionar con discord.js. Estoy planeando agregar varias funciones más complejas, por lo que reemplazar lib.start() con msg.channel.send('Game Started') no solucionará mi problema. ¿Hay alguna manera de que los comandos discord.js funcionen en lib.js para poder llamarlos a index.js?

índice.js

 const Discord = require('discord.js') const client = new Discord.Client(); const lib = require("./classes/lib"); const { token } = require('./Data/config.json'); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }) client.on('message', async msg => { if(msg.content.startsWith("m!")) { const command = msg.content.substring(2) switch(command) { //Calling 'start()' case "start game" : lib.start(); break; default: msg.channel.send('Unknown Command'); } } }) client.login(token)

lib.js

 function start() { msg.channel.send('Game Started'); //Trying to get this to work } module.exports = {start};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pasar una referencia al mensaje en la función

 client.on('message', async msg => { if(msg.content.startsWith("m!")) { const command = msg.content.substring(2) switch(command) { //Calling 'start()' case "start game" : lib.start(msg); break; default: msg.channel.send('Unknown Command'); } } })
 function start(msg) { msg.channel.send('Game Started'); } module.exports = {start};

Probablemente también desee hacer que las funciones de start y posteriores sean async , solo recuerde await cuando se las llame.

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!