@@ -60,6 +60,7 @@ export async function startDiscordBot() {
6060 // Define the bot token
6161 const token = process . env . DISCORD_TOKEN ! ;
6262 const clientId = process . env . DISCORD_CLIENT_ID ! ;
63+ const ownerGuildId = process . env . DISCORD_OWNER_GUILD_ID ;
6364
6465 // Check if token and clientId are available
6566 if ( ! token ) {
@@ -279,7 +280,16 @@ export async function startDiscordBot() {
279280 } )
280281
281282 // Slash commands
282- const commands = Object . values ( discordCommands ) . map ( command => command . definition )
283+ const allCommands = Object . values ( discordCommands ) ;
284+
285+ // Separate regular commands from owner-only commands
286+ const regularCommands = allCommands
287+ . filter ( cmd => ! cmd . ownerOnly )
288+ . map ( cmd => cmd . definition ) ;
289+
290+ const ownerOnlyCommands = allCommands
291+ . filter ( cmd => cmd . ownerOnly )
292+ . map ( cmd => cmd . definition ) ;
283293
284294 // Register commands with Discord API
285295 const rest = new REST ( { version : '10' } ) . setToken ( token ) ;
@@ -290,11 +300,33 @@ export async function startDiscordBot() {
290300 body : 'Started refreshing application (/) commands.'
291301 } ) ;
292302
293- // Register commands globally (this applies to all guilds)
303+ // Register regular commands globally (this applies to all guilds)
294304 await rest . put ( Routes . applicationCommands ( clientId ) , {
295- body : commands . map ( command => command . toJSON ( ) ) , // Convert CommandBuilder to JSON
305+ body : regularCommands . map ( command => command . toJSON ( ) ) , // Convert CommandBuilder to JSON
296306 } ) ;
297307
308+ logger . emit ( {
309+ severityText : 'INFO' ,
310+ body : `Successfully registered ${ regularCommands . length } global command(s).`
311+ } ) ;
312+
313+ // Register owner-only commands to the specific guild if configured
314+ if ( ownerGuildId && ownerOnlyCommands . length > 0 ) {
315+ await rest . put ( Routes . applicationGuildCommands ( clientId , ownerGuildId ) , {
316+ body : ownerOnlyCommands . map ( command => command . toJSON ( ) ) ,
317+ } ) ;
318+
319+ logger . emit ( {
320+ severityText : 'INFO' ,
321+ body : `Successfully registered ${ ownerOnlyCommands . length } owner-only command(s) to guild ${ ownerGuildId } .`
322+ } ) ;
323+ } else if ( ownerOnlyCommands . length > 0 ) {
324+ logger . emit ( {
325+ severityText : 'WARN' ,
326+ body : 'DISCORD_OWNER_GUILD_ID not set. Owner-only commands will not be registered.'
327+ } ) ;
328+ }
329+
298330 logger . emit ( {
299331 severityText : 'INFO' ,
300332 body : 'Successfully reloaded application (/) commands.'
0 commit comments