better support for sanboxing commands

This commit is contained in:
Nathaniel Mason 2022-04-22 21:01:17 +01:00
parent 984aaecc53
commit f921a67608
2 changed files with 38 additions and 20 deletions

View file

@ -5,8 +5,12 @@
"release": "anitrox_dev", "release": "anitrox_dev",
"build": "Stable", "build": "Stable",
"footerTxt": "Anitrox, made with <3 by IDeletedSystem64 | 2018-2022", "footerTxt": "Anitrox, made with <3 by IDeletedSystem64 | 2018-2022",
"sandbox": false, "sandbox": {
"sandboxGuild": "Set the value above to true and put a server ID here to use local slash commands instead of global. Used for debugging purposes", "enabled": false,
"id": "788391989460205571",
"refreshLocal": false,
"refreshGlobal": false
},
"statuses": [ "statuses": [
"with np!help", "with np!help",

View file

@ -32,27 +32,41 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({
client.on('error', (e) => console.log(`[ERROR] ${e}`)); client.on('error', (e) => console.log(`[ERROR] ${e}`));
client.on('warn', (e) => (`[WARN] ${e}`)); client.on('warn', (e) => (`[WARN] ${e}`));
client.once('ready', async () => { client.once('ready', async () => {
// const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands; const sandboxSettings = config.sandbox;
const localCommands = client.guilds.cache.get(sandboxSettings.id)?.commands;
const globalCommands = client.application.commands;
let existingLocal = await localCommands.fetch();
let existingGlobal = await globalCommands.fetch();
// Be careful about running the code below, there's a 200-per-day limit on creating slash commands if (sandboxSettings.enabled) {
// if (config.sandbox) { if (sandboxSettings.refreshLocal) {
// console.log('deleting previous commands from sandbox'); console.log('deleting previous local commands');
// const localCommands = await commands.fetch(); existingLocal.forEach(async x => {
// localCommands.forEach(async x => { await localCommands.delete(x);
// await commands.delete(x); });
// }); existingLocal = new Discord.Collection();
}
// console.log('deleting global commands'); if (sandboxSettings.refreshGlobal) {
// const globalCommands = await client.application.commands.fetch(); console.log('deleting previous global commands');
// globalCommands.forEach(async x => { existingGlobal.forEach(async x => {
// await client.application.commands.delete(x); await client.application.commands.delete(x);
// }); });
// } existingGlobal = new Discord.Collection();
}
}
// client.commands.forEach(async command => { client.commands.forEach(async command => {
// await commands.create(command); console.log(command);
// console.log(command); if (sandboxSettings.enabled && !existingLocal.map(x => x.name).includes(command.name)) {
// }); await localCommands.create(command);
// console.log(`created new local command ${command.name}`);
}
if (!existingGlobal.map(x => x.name).includes(command.name)) {
await globalCommands.create(command);
// console.log(`created new global command ${command.name}`);
}
});
console.clear(); console.clear();
console.log(' ___ _ __ '); console.log(' ___ _ __ ');