@@ -14,39 +14,36 @@ export class CommandsService {
14
14
private readonly slashCommandsService : SlashCommandsService
15
15
) { }
16
16
17
- public async register ( ) {
18
- if ( this . client . application . partial ) {
19
- await this . client . application . fetch ( ) ;
20
- }
17
+ public async registerAllCommands ( ) {
18
+ const guilds = new Set ( this . getCommandsByGuilds ( ) . keys ( ) ) ;
21
19
22
20
this . logger . log ( `Started refreshing application commands.` ) ;
23
- for ( const [ guild , commands ] of this . getCommandsByGuilds ( ) . entries ( ) ) {
24
- if ( commands . length === 0 ) {
25
- this . logger . log (
26
- `Skipping ${ guild ? `guild ${ guild } ` : 'global' } as it has no commands.`
27
- ) ;
28
- continue ;
29
- }
30
-
31
- const rawCommands = commands . flatMap ( command => command . toJSON ( ) ) ;
32
-
33
- await this . client . application . commands . set ( rawCommands , guild ) . catch ( error => {
34
- this . logger . error (
35
- `Failed to register application commands (${
36
- guild ? `in guild ${ guild } ` : 'global'
37
- } ): ${ error } `,
38
- error . stack
39
- ) ;
40
- } ) ;
21
+ for ( const guild of guilds ) {
22
+ await this . registerInGuild ( guild ) ;
41
23
}
42
24
this . logger . log ( `Successfully reloaded application commands.` ) ;
43
25
}
44
26
45
27
public async registerInGuild ( guildId : string ) {
46
- return this . client . application . commands . set (
47
- this . getGuildCommands ( guildId ) . flatMap ( command => command . toJSON ( ) ) ,
48
- guildId
49
- ) ;
28
+ const commands = this . getGuildCommands ( guildId ) ;
29
+
30
+ if ( commands . length === 0 ) {
31
+ this . logger . log (
32
+ `Skipping ${ guildId ? `guild ${ guildId } ` : 'global' } as it has no commands.`
33
+ ) ;
34
+ return ;
35
+ }
36
+
37
+ const rawCommands = commands . flatMap ( command => command . toJSON ( ) ) ;
38
+
39
+ return this . client . application . commands . set ( rawCommands , guildId ) . catch ( error => {
40
+ this . logger . error (
41
+ `Failed to register application commands (${
42
+ guildId ? `in guild ${ guildId } ` : 'global'
43
+ } ): ${ error } `,
44
+ error . stack
45
+ ) ;
46
+ } ) ;
50
47
}
51
48
52
49
public getCommands ( ) : CommandDiscovery [ ] {
0 commit comments