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

143
Vistas
Use client in event with event handler and ...args | Discord.js@13

I would like to use the client in the event, but I don't know how to hand it over without removing ... args

the event handler:

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });



const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
    const event = require(`./events/${file}`);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    } else {
        client.on(event.name, (...args) => event.execute(...args));
    }
}

and the event modul:

module.exports = {
    name: 'interactionCreate',
    async execute(client,interaction) {
       
   //... need client from code before here

    },
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Simply add client to the args!

if (event.once) {
  client.once(event.name, (...args) => event.execute(client, ...args));
} else {
  client.on(event.name, (...args) => event.execute(client, ...args));
}
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