Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
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
38 changes: 23 additions & 15 deletions scripts/deploy-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
import { Collection, REST, Routes } from 'discord.js';
import 'dotenv/config';

const redText = (text) => `\x1b[0;31m${text}\x1b[0m`;
const greenText = (text) => `\x1b[38;5;78m${text}\x1b[0m`;
const greyText = (text) => `\x1b[38;5;246m${text}\x1b[0m`;
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
const redText = (/** @type {string} */ text) => `\x1b[0;31m${text}\x1b[0m`;
const greenText = (/** @type {string} */ text) => `\x1b[38;5;78m${text}\x1b[0m`;
const greyText = (/** @type {string} */ text) => `\x1b[38;5;246m${text}\x1b[0m`;
const startSpinner = (/** @type {string} */ type, /** @type {string} */ totalCommands) => {
let i = 0;
return setInterval(() => {
process.stdout.write(`\r${greyText(frames[i])} Registering ${greyText(totalCommands)} ${type} application commands...`);
i = ++i % frames.length;
}, 80);
}

const TOKEN = process.env.DISCORD_TOKEN;
const CLIENT_ID = process.env.CLIENT_ID;
const SUPPORT_SERVER_ID = '770256165300338709';
Expand All @@ -13,21 +22,24 @@ if (!TOKEN || !CLIENT_ID)
throw new Error('Missing TOKEN or CLIENT_ID.');

const commandUtils = await import('../build/utils/CommandUtils.js').catch(() => {
console.error(`${redText('✘')} Code is not build yet. Run \`pnpm build\` first.`);
process.exit();
throw new Error(`${redText('✘')} Code is not build yet. Run \`pnpm build\` first.`);
});

const registerAllCommands = async (staffOnly = false) => {
// make sure CommandsMap is not empty
const commandsMap = new Collection();
await commandUtils.loadCommandFiles(commandsMap, new Collection());

const rest = new REST().setToken(TOKEN);


const commands = commandsMap
.filter((command) => (staffOnly ? command.staffOnly : !command.staffOnly))
.map((command) => command.data);
.filter((command) => (staffOnly ? command.staffOnly : !command.staffOnly))
.map((command) => command.data);

const type = staffOnly ? 'private' : 'public';
const totalCommands = commands.length.toString();
const spinner = startSpinner(type, totalCommands);

const rest = new REST().setToken(TOKEN);
const route = staffOnly
? Routes.applicationGuildCommands(CLIENT_ID, SUPPORT_SERVER_ID)
: Routes.applicationCommands(CLIENT_ID);
Expand All @@ -36,15 +48,13 @@ const registerAllCommands = async (staffOnly = false) => {
/** @type {any} */
const registerRes = await rest.put(route, { body: commands });

const type = staffOnly ? 'private' : 'public';
const totalRegistered =
registerRes.length === commands.length
? greenText(registerRes.length)
: redText(registerRes.length);

console.log(
`${greenText('✓')} Registered ${totalRegistered}${greyText('/')}${greenText(commands.length)} ${type} application commands.`,
);
clearInterval(spinner);
console.log(`\r${greenText('✓')} Registered ${totalRegistered}${greyText('/')}${greenText(totalCommands)} ${type} application commands.`); // Clear the spinner line and print "Done!"
};

const logHelp = () =>
Expand Down Expand Up @@ -73,6 +83,4 @@ if (process.argv) {

if (slicedArgs.length === 0) logHelp();
else await parseAndRun(allArgs);

process.exit();
}