🎨 reuse discord client when deploy commands

This commit is contained in:
Axel Olausson Holtenäs 2022-08-28 00:16:11 +02:00
parent 6ed5bb3cf3
commit f58a9b53ec

View file

@ -1,9 +1,7 @@
import logger from "../../middlewares/logger";
import { Client } from "discord.js";
import { REST } from "@discordjs/rest";
import { Routes } from "discord-api-types/v9";
import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10";
import { Client } from "discord.js";
import { ICommand } from "../../interfaces/Command"; import { ICommand } from "../../interfaces/Command";
import logger from "../../middlewares/logger";
export default async (client: Client) => { export default async (client: Client) => {
const commandList: Array<RESTPostAPIApplicationCommandsJSONBody> = []; const commandList: Array<RESTPostAPIApplicationCommandsJSONBody> = [];
@ -28,12 +26,8 @@ export default async (client: Client) => {
throw new Error(`Could not gather command list: ${error}`); throw new Error(`Could not gather command list: ${error}`);
}); });
const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN); await client.application?.commands
.set(commandList, process.env.DISCORD_GUILD_ID)
await rest
.put(Routes.applicationCommands(process.env.DISCORD_CLIENT_ID), {
body: commandList,
})
.then(async () => { .then(async () => {
logger.info(`Finished updating command list.`); logger.info(`Finished updating command list.`);
}) })
@ -42,16 +36,8 @@ export default async (client: Client) => {
}); });
if (process.env.NODE_ENV !== "production") { if (process.env.NODE_ENV !== "production") {
await rest await client.application?.commands
.put( .set(commandList)
Routes.applicationGuildCommands(
process.env.DISCORD_CLIENT_ID,
process.env.DISCORD_GUILD_ID
),
{
body: commandList,
}
)
.then(async () => logger.info(`Finished updating guild command list.`)) .then(async () => logger.info(`Finished updating guild command list.`))
.catch(async (error) => { .catch(async (error) => {
logger.error(`${error}`); logger.error(`${error}`);