Added comments and allowed passing null as loadcommand argument

This commit is contained in:
Ninjdai 2023-04-24 20:44:17 +02:00 committed by GitHub
parent 22ec12a1d4
commit ad698b9653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,14 @@
const { REST } = require('@discordjs/rest'); const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10'); const { Routes } = require('discord-api-types/v10');
const { token, clientId, guildId } = require('./config.json'); const { token, clientId, guildId } = require('./config.json');
const { Collection, SlashCommandBuilder } = require('discord.js') const { Collection, SlashCommandBuilder } = require('discord.js');
const { isBoolean } = require('util')
const fs = require('fs'); const fs = require('fs');
const rest = new REST({ version: '10' }).setToken(token); const rest = new REST({ version: '10' }).setToken(token);
function deploy_commands(client, loadcommands) { function deploy_commands(client, loadcommands) {
if (!isBoolean(loadcommands)) throw "type of loadcommands argument needs to be boolean"; if (typeof loadcommands !="boolean" && loadcommands != null) throw "loadcommands argument needs to be boolean or null";
const commands = []; const commands = [];
client.commands = new Collection(); client.commands = new Collection();
@ -24,13 +23,18 @@ function deploy_commands(client, loadcommands) {
console.log(`${category}/${command.data.name} chargé !`); console.log(`${category}/${command.data.name} chargé !`);
} }
} }
if (loadcommands){ if (loadcommands==true){
slashCommandLoad(client, commands); slashCommandLoad(client, commands);
console.log("Refreshed slash commands !");
} }
else{//Deletes slash commands else if(loadcommands==false){//Deletes slash commands
slashCommandLoad(client, []) slashCommandLoad(client, []);
console.log("Deleted slash commands !");
} }
} else{
console.log("Kept old commands");
}
};
async function slashCommandLoad(client, commands) { async function slashCommandLoad(client, commands) {
try { try {