@@ -11,6 +11,8 @@ import { db } from './db'
11
11
import { createMessageHandlers , createReactionHandlers } from './types/listeners'
12
12
import { startWebServer } from './web'
13
13
14
+ const DEBUG_COMMAND_IDS = process . argv . includes ( '--debug-command-ids' )
15
+
14
16
// Handle CLI flags before booting the bot
15
17
if ( process . argv . includes ( '--deploy-commands' ) ) {
16
18
await deployCommands ( )
@@ -31,6 +33,38 @@ const client = new Client({
31
33
32
34
client . once ( Events . ClientReady , async ( readyClient ) => {
33
35
console . log ( `Bot is ready, logged in as ${ readyClient . user . tag } ` )
36
+
37
+ // Optionally list all registered application commands and their IDs
38
+ if ( DEBUG_COMMAND_IDS ) {
39
+ try {
40
+ // Global application commands
41
+ const global = await readyClient . application ! . commands . fetch ( )
42
+ console . log ( `[Debug][Commands] Global commands: ${ global . size } ` )
43
+ for ( const [ , cmd ] of global ) {
44
+ console . log ( ` - /${ cmd . name } (${ cmd . id } )` )
45
+ }
46
+
47
+ // Guild-scoped commands per guild
48
+ for ( const [ , guild ] of readyClient . guilds . cache ) {
49
+ try {
50
+ const guildCmds = await guild . commands . fetch ( )
51
+ console . log (
52
+ `[Debug][Commands] Guild ${ guild . name } (${ guild . id } ) commands: ${ guildCmds . size } ` ,
53
+ )
54
+ for ( const [ , cmd ] of guildCmds ) {
55
+ console . log ( ` - /${ cmd . name } (${ cmd . id } )` )
56
+ }
57
+ } catch ( err ) {
58
+ console . warn (
59
+ `[Debug][Commands] Failed to fetch guild commands for ${ guild . name } (${ guild . id } )` ,
60
+ err ,
61
+ )
62
+ }
63
+ }
64
+ } catch ( err ) {
65
+ console . warn ( '[Debug][Commands] Failed to fetch application commands' , err )
66
+ }
67
+ }
34
68
for ( const [ , guild ] of client . guilds . cache ) {
35
69
try {
36
70
const active = await guild . channels . fetchActiveThreads ( )
0 commit comments