eu.astrogd.white-leopard/ci/deploy.ts

33 lines
955 B
TypeScript
Raw Permalink Normal View History

2022-11-24 02:12:52 +01:00
// Dotenv initialization
import path from "path";
import dotenv from "dotenv";
dotenv.config({ path: path.join(__dirname, "../.env") });
// Environment checking
2022-11-24 21:25:41 +01:00
const TOKEN = process.env["DEPLOY_TOKEN"];
const CLIENT_ID = process.env["DEPLOY_CLIENT_ID"];
2022-11-24 02:12:52 +01:00
if (!TOKEN) throw new ReferenceError("Environment variable TOKEN is missing");
if (!CLIENT_ID) throw new ReferenceError("Environment variable CLIENT_ID is missing");
// Deployment
import { REST, Routes } from "discord.js";
import { array as commands } from "../src/commands/ci";
const API = new REST({ version: "10" }).setToken(TOKEN);
(async () => {
try {
console.log("Start deploying slash commands globally");
const data = await API.put(
Routes.applicationCommands(CLIENT_ID),
{ body: commands },
);
console.log(`Successfully deployed ${(data as any).length} commands`);
}
catch (e) {
console.error(e);
}
})();