@@ -37,7 +37,10 @@ export class CommandRegistrar {
3737 /**
3838 * Gets the commands data.
3939 */
40- public getCommandsData ( ) : ( CommandData & { __metadata ?: CommandMetadata } ) [ ] {
40+ public getCommandsData ( ) : ( CommandData & {
41+ __metadata ?: CommandMetadata ;
42+ __applyId ( id : string ) : void ;
43+ } ) [ ] {
4144 const handler = this . commandkit . commandHandler ;
4245 // Use the public method instead of accessing private property
4346 const commands = handler . getCommandsArray ( ) ;
@@ -50,15 +53,20 @@ export class CommandRegistrar {
5053
5154 const __metadata = cmd . metadata ?? cmd . data . metadata ;
5255
53- const collections : ( CommandData & { __metadata ?: CommandMetadata } ) [ ] =
54- [ ] ;
56+ const collections : ( CommandData & {
57+ __metadata ?: CommandMetadata ;
58+ __applyId ( id : string ) : void ;
59+ } ) [ ] = [ ] ;
5560
5661 if ( cmd . data . chatInput ) {
5762 collections . push ( {
5863 ...json ,
5964 type : ApplicationCommandType . ChatInput ,
6065 description : json . description ?? 'No command description set.' ,
6166 __metadata,
67+ __applyId : ( id : string ) => {
68+ cmd . discordId = id ;
69+ } ,
6270 } ) ;
6371 }
6472
@@ -72,6 +80,9 @@ export class CommandRegistrar {
7280 description_localizations : undefined ,
7381 description : undefined ,
7482 __metadata,
83+ __applyId : ( id : string ) => {
84+ cmd . discordId = id ;
85+ } ,
7586 } ) ;
7687 }
7788
@@ -84,6 +95,9 @@ export class CommandRegistrar {
8495 description : undefined ,
8596 options : undefined ,
8697 __metadata,
98+ __applyId : ( id : string ) => {
99+ cmd . discordId = id ;
100+ } ,
87101 } ) ;
88102 }
89103
@@ -138,7 +152,10 @@ export class CommandRegistrar {
138152 * Updates the global commands.
139153 */
140154 public async updateGlobalCommands (
141- commands : ( CommandData & { __metadata ?: CommandMetadata } ) [ ] ,
155+ commands : ( CommandData & {
156+ __metadata ?: CommandMetadata ;
157+ __applyId ( id : string ) : void ;
158+ } ) [ ] ,
142159 ) {
143160 if ( ! commands . length ) return ;
144161
@@ -162,9 +179,20 @@ export class CommandRegistrar {
162179 body : commands . map ( ( c ) => ( {
163180 ...c ,
164181 __metadata : undefined ,
182+ __applyId : undefined ,
165183 } ) ) ,
166184 } ,
167- ) ) as CommandData [ ] ;
185+ ) ) as ( CommandData & { id : string } ) [ ] ;
186+
187+ // inject the command id into the command
188+ data . forEach ( ( c ) => {
189+ if ( ! c . id ) return ;
190+ const cmd = commands . find (
191+ ( co ) => co . name === c . name && co . type === c . type ,
192+ ) ;
193+ if ( ! cmd ) return ;
194+ cmd . __applyId ?.( c . id ) ;
195+ } ) ;
168196
169197 Logger . info (
170198 `✨ Refreshed ${ data . length } global application (/) commands` ,
@@ -178,7 +206,10 @@ export class CommandRegistrar {
178206 * Updates the guild commands.
179207 */
180208 public async updateGuildCommands (
181- commands : ( CommandData & { __metadata ?: CommandMetadata } ) [ ] ,
209+ commands : ( CommandData & {
210+ __metadata ?: CommandMetadata ;
211+ __applyId ( id : string ) : void ;
212+ } ) [ ] ,
182213 ) {
183214 if ( ! commands . length ) return ;
184215
@@ -242,9 +273,19 @@ export class CommandRegistrar {
242273 body : guildCommands . map ( ( b ) => ( {
243274 ...b ,
244275 __metadata : undefined ,
276+ __applyId : undefined ,
245277 } ) ) ,
246278 } ,
247- ) ) as CommandData [ ] ;
279+ ) ) as ( CommandData & { id : string } ) [ ] ;
280+
281+ data . forEach ( ( c ) => {
282+ if ( ! c . id ) return ;
283+ const cmd = commands . find (
284+ ( co ) => co . name === c . name && co . type === c . type ,
285+ ) ;
286+ if ( ! cmd ) return ;
287+ cmd . __applyId ?.( c . id ) ;
288+ } ) ;
248289
249290 count += data . length ;
250291 }
0 commit comments