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

272
Vistas
Discord.js Execute a Command Within Another Command

I am building a Discord bot, V12. I am now building a help command, with an embed and reaction emoji's. Here is a sample of my code:

if (reaction.emoji.name === RulesEmoji) {
   await message.channel.send("Test1");
}

It now sends a message when you react, but I want it to execute another file. Something like:

if (reaction.emoji.name === RulesEmoji) {
   await execute("./otherfile.js");
}

So does someone know how to execute another file in my commands folder within a command?

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

0

Create a function that handles it for you

async function execute(file, ...args) {
  const f = require(file)
  if (!f) throw new Error("Invalid file")
  return f.execute(...args)
}

This assumes that the files look like this:

module.exports = {
  async execute(reaction) {
    // execute function
  }
}

Execute with this:

await execute("./otherfile.js", reaction)
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