Skip to content

Commit 7b12677

Browse files
committed
fix: slash command loader does not load nested files
1 parent 9b10012 commit 7b12677

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/loaders/slashCommands.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ export async function loadSlashCommands() {
3636

3737
for (const scFile of slashCommandFiles) {
3838
const fileBasename = path.basename(scFile, FILE_EXT)
39-
const fileWithExt = path.basename(scFile)
39+
const fileDirectory = path.dirname(scFile).replaceAll(path.sep, "/")
4040

4141
try {
4242
// Import the module to check if it exists and has a default export
43-
const rawModule = await import(`../commands/slash/${fileWithExt}`)
43+
const rawModule = await import(`../commands/slash/${scFile}`)
4444
const commandModule = rawModule.default?.default
4545
? rawModule.default
4646
: rawModule
@@ -62,7 +62,20 @@ export async function loadSlashCommands() {
6262
}
6363

6464
// Save the file name in the config (used during execution)
65-
config.fileName = fileWithExt
65+
config.fileName = scFile
66+
67+
// Get the first directory name of the file directory that isn't inside parenthesis
68+
const directories = fileDirectory.split("/")
69+
const categoryIndex = directories.findIndex(
70+
(dir) => !dir.startsWith("(") && !dir.endsWith(")")
71+
)
72+
const category =
73+
categoryIndex !== -1
74+
? directories.slice(categoryIndex).join("/").trim()
75+
: undefined
76+
if (category && category !== ".") {
77+
config.category = category
78+
}
6679

6780
slashCommands.push(buildSlashCommand(config, command))
6881
slashConfigs.push(config)

0 commit comments

Comments
 (0)