@@ -14,8 +14,9 @@ import {
1414 REST ,
1515 Routes ,
1616} from "discord.js" ;
17- import guardianCommands from "../roles/00_guardians /index.js" ;
17+ import nodeOperatorCommands from "../roles/nodeOperators /index.js" ;
1818import adminsCommands from "../roles/admins/index.js" ;
19+ import { logger } from "../utils/logger.js" ;
1920
2021// Extended Discord client interface with commands collection
2122export interface ExtendedClient extends Client {
@@ -34,7 +35,7 @@ export class Discord {
3435 */
3536 static new = async ( ) => {
3637 try {
37- console . log ( "Initializing Discord client" ) ;
38+ logger . info ( "Initializing Discord client" ) ;
3839
3940 // Initialize Discord client with required intents
4041 const client = new Client ( {
@@ -55,7 +56,7 @@ export class Discord {
5556
5657 return new Discord ( client ) ;
5758 } catch ( error ) {
58- console . error ( "Error initializing Discord client:" , error ) ;
59+ logger . error ( { error } , "Error initializing Discord client" ) ;
5960 throw error ;
6061 }
6162 } ;
@@ -69,15 +70,18 @@ export class Discord {
6970 * Error event handler
7071 */
7172 client . once ( "error" , ( error ) => {
72- console . error ( "Error:" , error ) ;
73+ logger . error ( { error } , "Discord client error" ) ;
7374 } ) ;
7475
7576 /**
7677 * Ready event handler - called when bot is initialized
7778 */
7879 client . once ( "ready" , async ( ) => {
79- console . log ( "Sparta bot is ready!" ) ;
80- console . log ( "Bot Client ID: " , process . env . BOT_CLIENT_ID ) ;
80+ logger . info ( "Sparta bot is ready!" ) ;
81+ logger . info (
82+ { clientId : process . env . BOT_CLIENT_ID } ,
83+ "Bot connected with Client ID"
84+ ) ;
8185 Discord . deployCommands ( client ) ;
8286 } ) ;
8387
@@ -95,15 +99,21 @@ export class Discord {
9599 const channel = interaction . channel as TextChannel ;
96100
97101 const reply = await command . execute ( interaction ) ;
98- console . log ( "Command:" , {
99- name : interaction . commandName ,
100- channel : channel . name ,
101- user : interaction . user . username ,
102- date : interaction . createdAt ,
103- result : reply ,
104- } ) ;
102+ logger . info (
103+ {
104+ name : interaction . commandName ,
105+ channel : channel . name ,
106+ user : interaction . user . username ,
107+ date : interaction . createdAt ,
108+ result : reply ,
109+ } ,
110+ "Command executed"
111+ ) ;
105112 } catch ( error ) {
106- console . error ( error ) ;
113+ logger . error (
114+ { error, command : interaction . commandName } ,
115+ "Error executing command"
116+ ) ;
107117 await interaction . reply ( {
108118 content : "There was an error executing this command!" ,
109119 flags : MessageFlags . Ephemeral ,
@@ -122,10 +132,10 @@ export class Discord {
122132 ) ;
123133
124134 try {
125- console . log ( "Started refreshing application (/) commands. " ) ;
135+ logger . info ( "Started refreshing application (/) commands" ) ;
126136
127137 const commandsData = Object . values ( {
128- ...guardianCommands ,
138+ ...nodeOperatorCommands ,
129139 ...adminsCommands ,
130140 } ) . map ( ( command ) => command . data . toJSON ( ) ) ;
131141
@@ -140,16 +150,16 @@ export class Discord {
140150 ) ;
141151
142152 for ( const command of Object . values ( {
143- ...guardianCommands ,
153+ ...nodeOperatorCommands ,
144154 ...adminsCommands ,
145155 } ) ) {
146156 client . commands . set ( command . data . name , command ) ;
147- console . log ( `Registered command: ${ command . data . name } ` ) ;
157+ logger . debug ( `Registered command: ${ command . data . name } ` ) ;
148158 }
149159
150- console . log ( "Successfully reloaded application (/) commands. " ) ;
160+ logger . info ( "Successfully reloaded application (/) commands" ) ;
151161 } catch ( error ) {
152- console . error ( error ) ;
162+ logger . error ( { error } , "Error deploying commands" ) ;
153163 }
154164 }
155165
0 commit comments