@@ -14,8 +14,9 @@ import {
14
14
REST ,
15
15
Routes ,
16
16
} from "discord.js" ;
17
- import guardianCommands from "../roles/00_guardians /index.js" ;
17
+ import nodeOperatorCommands from "../roles/nodeOperators /index.js" ;
18
18
import adminsCommands from "../roles/admins/index.js" ;
19
+ import { logger } from "../utils/logger.js" ;
19
20
20
21
// Extended Discord client interface with commands collection
21
22
export interface ExtendedClient extends Client {
@@ -34,7 +35,7 @@ export class Discord {
34
35
*/
35
36
static new = async ( ) => {
36
37
try {
37
- console . log ( "Initializing Discord client" ) ;
38
+ logger . info ( "Initializing Discord client" ) ;
38
39
39
40
// Initialize Discord client with required intents
40
41
const client = new Client ( {
@@ -55,7 +56,7 @@ export class Discord {
55
56
56
57
return new Discord ( client ) ;
57
58
} catch ( error ) {
58
- console . error ( "Error initializing Discord client:" , error ) ;
59
+ logger . error ( { error } , "Error initializing Discord client" ) ;
59
60
throw error ;
60
61
}
61
62
} ;
@@ -69,15 +70,18 @@ export class Discord {
69
70
* Error event handler
70
71
*/
71
72
client . once ( "error" , ( error ) => {
72
- console . error ( "Error:" , error ) ;
73
+ logger . error ( { error } , "Discord client error" ) ;
73
74
} ) ;
74
75
75
76
/**
76
77
* Ready event handler - called when bot is initialized
77
78
*/
78
79
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
+ ) ;
81
85
Discord . deployCommands ( client ) ;
82
86
} ) ;
83
87
@@ -95,15 +99,21 @@ export class Discord {
95
99
const channel = interaction . channel as TextChannel ;
96
100
97
101
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
+ ) ;
105
112
} catch ( error ) {
106
- console . error ( error ) ;
113
+ logger . error (
114
+ { error, command : interaction . commandName } ,
115
+ "Error executing command"
116
+ ) ;
107
117
await interaction . reply ( {
108
118
content : "There was an error executing this command!" ,
109
119
flags : MessageFlags . Ephemeral ,
@@ -122,10 +132,10 @@ export class Discord {
122
132
) ;
123
133
124
134
try {
125
- console . log ( "Started refreshing application (/) commands. " ) ;
135
+ logger . info ( "Started refreshing application (/) commands" ) ;
126
136
127
137
const commandsData = Object . values ( {
128
- ...guardianCommands ,
138
+ ...nodeOperatorCommands ,
129
139
...adminsCommands ,
130
140
} ) . map ( ( command ) => command . data . toJSON ( ) ) ;
131
141
@@ -140,16 +150,16 @@ export class Discord {
140
150
) ;
141
151
142
152
for ( const command of Object . values ( {
143
- ...guardianCommands ,
153
+ ...nodeOperatorCommands ,
144
154
...adminsCommands ,
145
155
} ) ) {
146
156
client . commands . set ( command . data . name , command ) ;
147
- console . log ( `Registered command: ${ command . data . name } ` ) ;
157
+ logger . debug ( `Registered command: ${ command . data . name } ` ) ;
148
158
}
149
159
150
- console . log ( "Successfully reloaded application (/) commands. " ) ;
160
+ logger . info ( "Successfully reloaded application (/) commands" ) ;
151
161
} catch ( error ) {
152
- console . error ( error ) ;
162
+ logger . error ( { error } , "Error deploying commands" ) ;
153
163
}
154
164
}
155
165
0 commit comments