Skip to content

Commit

Permalink
Reload app commands on bot startup (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brainicism authored Oct 23, 2023
1 parent 1675e9c commit 1235755
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/commands/admin/appcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default class AppCommandsCommand implements BaseCommand {
}

await updateAppCommands(appCommandType);
await State.ipc.allClustersCommand("fetch_app_command_ids");
await sendInfoMessage(MessageContext.fromMessage(message), {
title: "Commands Updated",
});
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/discord_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2066,9 +2066,6 @@ export const updateAppCommands = async (
appCommandType = AppCommandsAction.RELOAD
): Promise<void> => {
const isProd = process.env.NODE_ENV === EnvType.PROD;
const debugServer = State.client.guilds.get(
process.env.DEBUG_SERVER_ID as string
);

let commandStructures: Eris.ApplicationCommandStructure[] = [];

Expand Down Expand Up @@ -2173,6 +2170,10 @@ export const updateAppCommands = async (
if (isProd) {
await State.client.bulkEditCommands(commandStructures);
} else {
const debugServer = State.client.guilds.get(
process.env.DEBUG_SERVER_ID as string
);

if (debugServer) {
await State.client.bulkEditGuildCommands(
debugServer.id,
Expand All @@ -2182,6 +2183,8 @@ export const updateAppCommands = async (
logger.error("Debug server unexpectedly unavailable");
}
}

await State.ipc.allClustersCommand("fetch_app_command_ids");
};

/**
Expand Down
6 changes: 5 additions & 1 deletion src/kmq_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { BaseClusterWorker } from "eris-fleet";
import { IPCLogger } from "./logger";
import { config } from "dotenv";
import { durationSeconds } from "./helpers/utils";
import { fetchAppCommandIDs } from "./helpers/discord_utils";
import { fetchAppCommandIDs, updateAppCommands } from "./helpers/discord_utils";
import {
registerIntervals,
reloadCaches,
updateBotStatus,
} from "./helpers/management_utils";
import AppCommandsAction from "./enums/app_command_action";
import EnvType from "./enums/env_type";
import EvalCommand from "./commands/admin/eval";
import ReloadCommand from "./commands/admin/reload";
Expand Down Expand Up @@ -278,5 +279,8 @@ export default class BotWorker extends BaseClusterWorker {
process.env.NODE_ENV
}' mode (${durationSeconds(State.processStartTime, Date.now())}s)`
);

logger.info("Reloading app commands");
updateAppCommands(AppCommandsAction.RELOAD);
}
}

0 comments on commit 1235755

Please sign in to comment.