pnp-scheduler/source/Discord/CommandDeployer.ts
2025-06-18 22:53:54 +02:00

28 lines
No EOL
964 B
TypeScript

import {DiscordClient} from "./DiscordClient";
import {Logger} from "log4js";
import {REST, Routes, Snowflake} from "discord.js";
import Commands from "./Commands/Commands";
export class CommandDeployer {
constructor(
private readonly applicationId: string,
private readonly restClient: REST,
private readonly commands: Commands,
private readonly logger: Logger
) {
}
public async deployServer(serverId: Snowflake) {
const commandInfos = this.commands.getJsonDefinitions();
this.logger.debug(`Started refreshing ${commandInfos.length} application (/) commands for ${serverId}.`);
// The put method is used to fully refresh all commands in the guild with the current set
await this.restClient.put(
Routes.applicationGuildCommands(this.applicationId, serverId),
{body: commandInfos},
);
this.logger.debug(`Successfully reloaded ${commandInfos.length} application (/) commands for ${serverId}.`);
}
}