🚚 move deployCommands to handlers

This commit is contained in:
Axel Olausson Holtenäs 2022-04-13 02:51:05 +02:00
parent 3a24cc1d72
commit bca90d4741
No known key found for this signature in database
GPG key ID: 9347A5E873995701
2 changed files with 42 additions and 41 deletions

View file

@ -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);
});
}
};

View file

@ -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);
});
}
};