From 30c31388a1b569b0819581a5af2f0bfaa561a5b1 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 10 Jun 2022 22:27:44 -0400 Subject: [PATCH] Move One Time Scripts back to root --- _clear-commands.js | 27 +++++++++++++++++++++++++++ _deploy-commands.js | 40 ++++++++++++++++++++++++++++++++++++++++ _deploy_global.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 _clear-commands.js create mode 100644 _deploy-commands.js create mode 100644 _deploy_global.js diff --git a/_clear-commands.js b/_clear-commands.js new file mode 100644 index 0000000..869c90d --- /dev/null +++ b/_clear-commands.js @@ -0,0 +1,27 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const clientId = process.env.clientId; +const { guildId } = require('../config.json'); +const token = process.env.TOKEN; + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationGuildCommands(clientId, guildId), + { body: '' }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file diff --git a/_deploy-commands.js b/_deploy-commands.js new file mode 100644 index 0000000..5ba21ce --- /dev/null +++ b/_deploy-commands.js @@ -0,0 +1,40 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const { guildId } = require('./config.json'); +const clientId = process.env.clientId; +const token = process.env.TOKEN; +const fs = require('fs'); + +const commands = []; +const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js')); + +for (const file of commandFiles) { + const command = require(`./slash-commands/${file}`); + if (command.data != undefined) { + commands.push(command.data.toJSON()); + } +} + +console.log(commands); + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationGuildCommands(clientId, guildId), + { body: commands }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file diff --git a/_deploy_global.js b/_deploy_global.js new file mode 100644 index 0000000..6152f49 --- /dev/null +++ b/_deploy_global.js @@ -0,0 +1,40 @@ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); + +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const { guildId } = require('./config.json'); +const clientId = process.env.clientId; +const token = process.env.TOKEN; +const fs = require('fs'); + +const commands = []; +const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js')); + +for (const file of commandFiles) { + const command = require(`./slash-commands/${file}`); + if (command.data != undefined) { + commands.push(command.data.toJSON()); + } +} + +console.log(commands); + +const rest = new REST({ version: '9' }).setToken(token); + +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + + await rest.put( + Routes.applicationGuildCommands(clientId), + { body: commands }, + ); + + console.log('Successfully reloaded application (/) commands.'); + process.exit(); + } catch (error) { + console.error(error); + } +})(); \ No newline at end of file