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

269
Views
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 answers
Answer question

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 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!