import * as fs from "fs"; import * as path from "path"; import {Message} from "discord.js"; import {Command} from "../Command"; import {CustomClient} from "../index"; const {userDict} = require("../config.json"); const reloadcommand = new Command( 'reloadcommand', async (message, args, client) => { if (args.length) await reloadSingleCommand(args[0].toLowerCase(), client, message); else await reloadCommands(client, message); }, { description: "Reloads either every, or a given command module.", aliases: ["reload"], usage: "[commandName]", permissions: { users: [userDict.misabiko], groups: [] } } ); export default reloadcommand; async function reloadSingleCommand(commandName : string, client : CustomClient, message : Message) { const {commandCollection} = client; if (commandName === 'reloadcommand') return message.channel.send("You have to restart the bot to reload this command."); if (!commandCollection.has(commandName)) return message.channel.send(`The ${commandName} command doesn't exist.`); if (await client.importCommand(`./${commandName}.js`, message)) await message.channel.send(`Successfully reloaded the ${commandName} command.`); else await message.channel.send(`Failed to reload the ${commandName} command.`); } async function reloadCommands(client : CustomClient, message : Message) { const {commandCollection} = client; commandCollection.clear([ commandCollection.get('reloadcommand') ]); const commandFiles = fs.readdirSync(__dirname).filter(file => file.endsWith(".js")); let hadErrors = false; for (const file of commandFiles) if (file !== "reloadcommand.js") hadErrors = hadErrors || !(await client.importCommand(path.join(__dirname, file), message)); if (hadErrors) await message.channel.send(`Failed to reload some commands.`); else await message.channel.send(`Successfully reloaded the commands.`); }