Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload app commands on bot startup #1749

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading