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?
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)