1
- import { CacheType , Events , Interaction , Message } from 'discord.js' ;
1
+ import {
2
+ ApplicationCommandType ,
3
+ CacheType ,
4
+ Events ,
5
+ Interaction ,
6
+ Message ,
7
+ } from 'discord.js' ;
2
8
import type {
3
9
CommandData ,
4
10
CommandFileObject ,
@@ -185,6 +191,8 @@ export class CommandHandler {
185
191
commandObj . category = commandCategory ;
186
192
}
187
193
194
+ Logger . info ( `Loaded command: ${ commandObj . data . name } ` ) ;
195
+
188
196
this . #data. commands . push ( commandObj ) ;
189
197
}
190
198
@@ -193,19 +201,56 @@ export class CommandHandler {
193
201
194
202
const commands = handler . getCommandsArray ( ) ;
195
203
196
- // this.#data.commands.push(...commands);
197
-
198
204
for ( const cmd of commands ) {
199
- const idx = this . #data. commands . findIndex (
200
- ( c ) => c . data . name === cmd . name ,
201
- ) ;
205
+ const json : CommandData =
206
+ 'toJSON' in cmd . data . command
207
+ ? cmd . data . command . toJSON ( )
208
+ : cmd . data . command ;
202
209
203
- if ( idx !== - 1 ) {
204
- // @ts -ignore
205
- this . #data. commands [ idx ] = { data : cmd } ;
206
- } else {
207
- // @ts -ignore
208
- this . #data. commands . push ( { data : cmd } ) ;
210
+ const additionals : CommandData [ ] = [ json ] ;
211
+
212
+ if (
213
+ cmd . data . userContextMenu &&
214
+ json . type !== ApplicationCommandType . User
215
+ ) {
216
+ additionals . push ( {
217
+ ...json ,
218
+ type : ApplicationCommandType . User ,
219
+ options : undefined ,
220
+ description_localizations : undefined ,
221
+ // @ts -ignore
222
+ description : undefined ,
223
+ } ) ;
224
+ }
225
+
226
+ if (
227
+ cmd . data . messageContextMenu &&
228
+ json . type !== ApplicationCommandType . Message
229
+ ) {
230
+ additionals . push ( {
231
+ ...json ,
232
+ type : ApplicationCommandType . Message ,
233
+ description_localizations : undefined ,
234
+ // @ts -ignore
235
+ description : undefined ,
236
+ options : undefined ,
237
+ } ) ;
238
+ }
239
+
240
+ for ( const variant of additionals ) {
241
+ const idx = this . #data. commands . findIndex (
242
+ ( c ) => c . data . name === variant . name && c . data . type === variant . type ,
243
+ ) ;
244
+
245
+ if ( idx !== - 1 ) {
246
+ // @ts -ignore
247
+ this . #data. commands [ idx ] = { data : variant } ;
248
+ } else {
249
+ // @ts -ignore
250
+ this . #data. commands . push ( { data : variant } ) ;
251
+ }
252
+
253
+ Logger . info ( `(app ✨) Loaded command: ${ variant . name } ` ) ;
209
254
}
210
255
}
211
256
}
0 commit comments