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

View file

@ -8,14 +8,8 @@ const {
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
console.log(client.commands);
var reloadCommands = require("./util/reloadCommands.js")
reloadCommands(client)
client.once('ready', () => {
console.log('Ready!');
@ -44,6 +38,7 @@ client.on('message', async message => {
switch (commandName) {
case "ban":
case "botinfo":
case "reload":
command.execute(message, client, args);
break;
case "say":
@ -57,7 +52,6 @@ client.on('message', async message => {
command.execute(message)
}
} catch (error) {
message.channel.send("That command either does not exist, or is broken.")
console.log(`${error}\n-------`)
}
});