Add support for reloading modules(commands) without restarting the bot.

This commit is contained in:
SileNce5k 2021-03-08 20:30:33 +01:00
parent 35d47e4a11
commit acd2e2a502
No known key found for this signature in database
GPG key ID: C507260E7F2583AD
3 changed files with 61 additions and 9 deletions

27
util/reloadCommands.js Normal file
View file

@ -0,0 +1,27 @@
const fs = require('fs')
const filepath = 'commands/'
module.exports = function (client) { //TODO: Add ability to reload specified commands with arguments
let commandFiles = fs.readdirSync(filepath).filter(file => file.endsWith('.js'));
if (client.commands.size != 0) {
for (const i of commandFiles) {
console.log(i)
delete require.cache[require.resolve(`../${filepath}${i}`)];
}
}
console.log(client.commands.size)
client.commands.clear()
console.log("test")
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
client.commands.set(command.name, command);
}
//console.log(require.cache[require.resolve('../commands')])
}