Skip to content

Conversation

@hmd-ali
Copy link
Contributor

@hmd-ali hmd-ali commented Oct 5, 2025

No description provided.

@hmd-ali hmd-ali requested a review from wiktoriavh October 5, 2025 15:47
Copy link
Member

@wiktoriavh wiktoriavh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i made some suggestions.

Comment on lines 2 to 7
import { docsCommands } from '../commands/docs/index.js';
import { guidesCommand } from '../commands/guides/index.js';
import { type Command, predicate as commandPredicate } from '../commands/index.js';
import { pingCommand } from '../commands/ping.js';
import { tipsCommands } from '../commands/tips/index.js';
import { hasVarEvent } from '../events/has-var.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(suggestion) i recommend making a barrel file in /commands called index.ts which exports everything. then you don't need to import eveything in here, but instead import everything inside the command dir barrel file.

then you can do

// /command/index.ts
import { pingCommand } from "./ping";
// ... rest

export const commands = [pingCommand, tipsCommands, guidesCommand, docsCommands].flat();

Here you can also then manually remove a command if it should not be used.

Same thing with events then.

and then in this file you would just do

import { commands } from "@/commands"
// ... rest of code
const loadCommands = (): Map<string, Command> => {
// no filter needed, since we know from the import that it only has the neseccary ones
  return new Map(commands.map((command) => [command.data.name, command]));
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(question) What i don't understand, why do you import the commands and events here, just to manipulate them, and export them?

Comment on lines 64 to 86

/**
*
* @returns An array of events
*/
const loadEvents = (): DiscordEvent[] => {
const events = [hasVarEvent, readyEvent, justAskEvent, interactionCreateEvent].filter(
eventPredicate
);
return events as DiscordEvent[];
};

/**
*
* @returns A map of command names to commands
*/
const loadCommands = (): Map<string, Command> => {
const commands = [pingCommand, tipsCommands, guidesCommand, docsCommands].flat();
return new Map(commands.filter(commandPredicate).map((command) => [command.data.name, command]));
};

export const commands = loadCommands();
export const events = loadEvents();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(suggestion) as mentioned in my other comment, use a barrel file. in the barrel file you prepare the data as you need it.
so the loadCommands function then becomes this in the barrel file

export const commands = new Map([pingCommand, tipsCommands, guidesCommand, docsCommands].flat().map((command) => [command.data.name, command]));

Copy link
Member

@wiktoriavh wiktoriavh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@hmd-ali hmd-ali merged commit 93c2c29 into main Oct 7, 2025
1 check passed
@hmd-ali hmd-ali deleted the feat/switch-to-explicit-imports branch October 21, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants