File tree Expand file tree Collapse file tree 5 files changed +9
-20
lines changed Expand file tree Collapse file tree 5 files changed +9
-20
lines changed Original file line number Diff line number Diff line change @@ -18,4 +18,6 @@ MODERATORS_ROLE_IDS=849481536654803004
1818GUIDES_TRACKER_PATH = /app/data/guides-tracker.json
1919ADVENT_OF_CODE_TRACKER_PATH = /app/data/advent-of-code-tracker.json
2020
21+ CLEAR_GLOBAL_COMMANDS = true
22+
2123# Note: DISCORD_TOKEN & CLIENT_ID should be in .env.local (not committed)
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export const config = {
2222 } ,
2323 serverId : requireEnv ( 'SERVER_ID' ) ,
2424 fetchAndSyncMessages : true ,
25+ clearGlobalCommands : optionalEnv ( 'CLEAR_GLOBAL_COMMANDS' ) === 'true' ,
2526 guidesTrackerPath : optionalEnv ( 'GUIDES_TRACKER_PATH' ) ,
2627 adventOfCodeTrackerPath : requireEnv ( 'ADVENT_OF_CODE_TRACKER_PATH' ) ,
2728 roleIds : {
Original file line number Diff line number Diff line change 11import { ActivityType , Client , GatewayIntentBits } from 'discord.js' ;
2- import { commands } from './commands/index.js' ;
32import { config } from './env.js' ;
43import { events } from './events/index.js' ;
5- import { registerCommands } from './util/commands.js' ;
64import { registerEvents } from './util/events.js' ;
75
86// Create a new client instance
@@ -27,6 +25,5 @@ const client = new Client({
2725
2826// Register events and commands
2927await registerEvents ( client , events ) ;
30- await registerCommands ( client , commands ) ;
3128
3229void client . login ( config . discord . token ) ;
Original file line number Diff line number Diff line change @@ -9,23 +9,6 @@ export const createCommands = (commands: Array<Command>): Command[] => {
99 return commands . map ( createCommand ) ;
1010} ;
1111
12- export const registerCommands = async (
13- client : Client ,
14- commands : Map < string , Command >
15- ) : Promise < void > => {
16- const commandArray = Array . from ( commands . values ( ) ) . map ( ( cmd ) => cmd . data ) ;
17-
18- try {
19- await client . application ?. commands . set ( commandArray ) ;
20- commandArray . forEach ( ( cmd ) => {
21- console . log ( `Registered command: ${ cmd . type } , ${ cmd . name } ` ) ;
22- } ) ;
23- console . log ( `Registered ${ commandArray . length } commands globally.` ) ;
24- } catch ( error ) {
25- console . error ( 'Error registering commands:' , error ) ;
26- }
27- } ;
28-
2912export const buildCommandString = ( interaction : ChatInputCommandInteraction ) : string => {
3013 const commandName = interaction . commandName ;
3114 return `/${ commandName } ${ interaction . options . data . map ( ( option ) => `${ option . name } :${ option . value } ` ) . join ( ' ' ) } ` ;
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ export async function deployCommands(): Promise<RESTPutAPIApplicationCommandsRes
77
88 const rest = new REST ( { version : '10' } ) . setToken ( config . discord . token ) ;
99
10+ if ( config . clearGlobalCommands ) {
11+ console . log ( 'Clearing global commands...' ) ;
12+ await rest . put ( Routes . applicationCommands ( config . discord . clientId ) , { body : [ ] } ) ;
13+ console . log ( 'Global commands cleared.' ) ;
14+ }
15+
1016 const result = ( await rest . put (
1117 Routes . applicationGuildCommands ( config . discord . clientId , config . serverId ) ,
1218 {
You canβt perform that action at this time.
0 commit comments