Squashed commit of the following:
commite8a57468deAuthor: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 11:10:56 2025 -0400 Add record command commit5a8ca6bb54Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 11:10:30 2025 -0400 Move context menus to their own folder commit2d7c14ed7aMerge:33a6ba85107759Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 10:54:27 2025 -0400 Merge branch 'alt-data' into records commit5107759923Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Fri May 30 15:26:21 2025 -0400 Recursive alt lookup data
This commit is contained in:
@@ -13,27 +13,40 @@ export async function refreshCommands(client: Client) {
|
||||
try {
|
||||
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];
|
||||
const guildCommands: { [id: string]: RESTPostAPIApplicationCommandsJSONBody[] } = {};
|
||||
const commandFiles = fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
|
||||
const commandFiles = {
|
||||
commands: fs.readdirSync(`${ROOT_DIR}/commands`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
|
||||
'context-menus': fs.readdirSync(`${ROOT_DIR}/context-menus`).filter(file => file.endsWith('.js') || file.endsWith('.ts')),
|
||||
};
|
||||
|
||||
for (const file of commandFiles) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const command: Command = require(`${ROOT_DIR}/commands/${file}`).default;
|
||||
let data: RESTPostAPIApplicationCommandsJSONBody;
|
||||
if (typeof (command.data) == 'function') {
|
||||
data = (await command.data(client)).toJSON();
|
||||
} else {
|
||||
data = command.data.toJSON();
|
||||
}
|
||||
for (const [folderName, files] of Object.entries(commandFiles)) {
|
||||
for (const file of files) {
|
||||
const p = `${ROOT_DIR}/${folderName}/${file}`;
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const command: Command = require(p).default;
|
||||
|
||||
if (!command.guilds) {
|
||||
commands.push(data);
|
||||
} else {
|
||||
for (const id of command.guilds) {
|
||||
if (!guildCommands[id]) guildCommands[id] = [];
|
||||
guildCommands[id].push(data);
|
||||
if (!command) {
|
||||
console.warn(`File at ${p} has no export. Skipping registering.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
let data: RESTPostAPIApplicationCommandsJSONBody;
|
||||
if (typeof (command.data) == 'function') {
|
||||
data = (await command.data(client)).toJSON();
|
||||
} else {
|
||||
data = command.data.toJSON();
|
||||
}
|
||||
|
||||
if (!command.guilds) {
|
||||
commands.push(data);
|
||||
} else {
|
||||
for (const id of command.guilds) {
|
||||
if (!guildCommands[id]) guildCommands[id] = [];
|
||||
guildCommands[id].push(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
console.log('Global commands: ' + commands.length);
|
||||
|
||||
Reference in New Issue
Block a user