@@ -36,11 +36,11 @@ export async function loadSlashCommands() {
36
36
37
37
for ( const scFile of slashCommandFiles ) {
38
38
const fileBasename = path . basename ( scFile , FILE_EXT )
39
- const fileWithExt = path . basename ( scFile )
39
+ const fileDirectory = path . dirname ( scFile ) . replaceAll ( path . sep , "/" )
40
40
41
41
try {
42
42
// 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 } ` )
44
44
const commandModule = rawModule . default ?. default
45
45
? rawModule . default
46
46
: rawModule
@@ -62,7 +62,20 @@ export async function loadSlashCommands() {
62
62
}
63
63
64
64
// 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
+ }
66
79
67
80
slashCommands . push ( buildSlashCommand ( config , command ) )
68
81
slashConfigs . push ( config )
0 commit comments