diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts new file mode 100644 index 0000000..81eab86 --- /dev/null +++ b/src/handlers/deployCommands.ts @@ -0,0 +1,42 @@ +import { devMode, bot } from "../../config.json"; +import logger from "../logger"; +import fs from "fs"; +import { REST } from "@discordjs/rest"; +import { Routes } from "discord-api-types/v9"; + +export default async () => { + const commands = []; + const commandFiles = fs.readdirSync("./src/commands"); + + for (const file of commandFiles) { + // eslint-disable-next-line global-require + const command = require(`../commands/${file}`); + commands.push(command.default.data.toJSON()); + } + + const rest = new REST({ version: "9" }).setToken(bot?.token); + + await rest + .put(Routes.applicationCommands(bot?.clientId), { + body: commands, + }) + .then(async () => + logger.info("Successfully registered application commands.") + ) + .catch(async (error) => { + logger.error(error); + }); + + if (devMode) { + await rest + .put(Routes.applicationGuildCommands(bot?.clientId, bot?.guildId), { + body: commands, + }) + .then(async () => + logger.info("Successfully registered guild application commands.") + ) + .catch(async (error) => { + logger.error(error); + }); + } +}; diff --git a/src/helpers/deployCommands.ts b/src/helpers/deployCommands.ts deleted file mode 100644 index b741a9a..0000000 --- a/src/helpers/deployCommands.ts +++ /dev/null @@ -1,41 +0,0 @@ -import config from "../../config.json"; -import logger from "../handlers/logger"; -import fs from "fs"; -import { REST } from "@discordjs/rest"; -import { Routes } from "discord-api-types/v9"; - -export default async () => { - const commands = []; - const commandFiles = fs.readdirSync("./src/commands"); - - for (const file of commandFiles) { - // eslint-disable-next-line global-require - const command = require(`../commands/${file}`); - commands.push(command.default.data.toJSON()); - } - - const rest = new REST({ version: "9" }).setToken(config.bot.token); - - await rest.put(Routes.applicationCommands(config.bot.clientId), { - body: commands, - }); - - if (config?.devMode) { - await rest - .put( - Routes.applicationGuildCommands( - config.bot.clientId, - config.bot.guildId - ), - { - body: commands, - } - ) - .then(async () => - logger.info("Successfully registered application commands.") - ) - .catch(async (err) => { - await logger.error(err); - }); - } -};