Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda