When `Config.dev` is true, the operator typically registers slash commands per-guild (Config.guildId) during iteration so they appear instantly. Once those leak past dev, the same commands show up in Discord twice — once from the dev guild registration and once from the global registration. Before doing the global PUT, also PUT an empty array against the dev guild so any stale per-guild commands are cleared. Behavior in production (Config.dev=false) is unchanged.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { REST, Routes } from "discord.js";
|
|
import { Config } from "./Config";
|
|
import { handler } from "../index";
|
|
import { Logger } from "./Logger";
|
|
|
|
async function main() {
|
|
const rest = new REST({ version: "10" }).setToken(Config.token);
|
|
const body = Array.from(handler.commands.values().filter(cmd => cmd.visible).map(cmd => cmd.metaData));
|
|
|
|
// 개발 모드에서는 Config.guildId 길드에 따로 등록된 슬래시가 남아
|
|
// 전역 명령어와 디스코드에 두 번 보이는 경우가 생긴다.
|
|
// 전역 등록 전에 해당 길드의 명령어를 전부 비워둔다.
|
|
if (Config.dev) {
|
|
await rest.put(
|
|
Routes.applicationGuildCommands(Config.appId, Config.guildId),
|
|
{ body: [] },
|
|
);
|
|
Logger.ready(`개발 길드(${Config.guildId}) 슬래시 전체 삭제 완료`);
|
|
}
|
|
|
|
// 전역 등록 (권장: 배포 파이프라인에서만 실행)
|
|
await rest.put(Routes.applicationCommands(Config.appId), { body });
|
|
Logger.ready(`전역 슬래시 등록 요청 완료: ${body.length}개`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
throw err instanceof Error ? err : new Error(String(err));
|
|
}); |