🚚 move deployCommands to handlers
This commit is contained in:
parent
3a24cc1d72
commit
bca90d4741
2 changed files with 42 additions and 41 deletions
42
src/handlers/deployCommands.ts
Normal file
42
src/handlers/deployCommands.ts
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
Loading…
Add table
Reference in a new issue