rcnlx
Version:
A cli to generate discord.js projects
65 lines (58 loc) • 1.79 kB
JavaScript
const fs = require("fs");
const path = require("path");
const symbols = require("log-symbols");
const chalk = require('chalk');
/**
* @param {*} filename file name
* @param {*} category category
* @param {*} command command
*/
module.exports = async function (filename, category, command, cooldown) {
try {
const dirPath = path.resolve(`src/commands/${category}`);
const filePath = path.resolve(`src/commands/${category}/${filename}.js`);
if (fs.existsSync(filePath))
return console.log
(chalk.red(`${symbols.error} ${filePath} already exists, please delete that file and try again!`)
);
if (fs.existsSync(dirPath)) {
fs.writeFileSync(
filePath,
`const { Client, Message, MessageEmbed } = require('discord.js');
module.exports = {
name: '${command}',
cooldown: ${cooldown},
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async(client, message, args) => {
}
}`
);
console.log(chalk.green(`${symbols.success} ${filename}.js has been created!`))
} else {
await fs.mkdirSync(dirPath);
await fs.writeFileSync(
filePath,
`const { Client, Message, MessageEmbed } = require('discord.js');
module.exports = {
name: '${command}',
cooldown: ${cooldown},
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async(client, message, args) => {
}
}`
);
console.log(chalk.green(`${symbols.success} ${filename}.js has been created!`))
}
} catch (err) {
console.log(chalk.red(`${symbols.error} Command Handler has not been initialised!`)
);
}
};