@@ -101,6 +101,9 @@ async function updateLoop() {
101101 . setTimestamp ( ) ;
102102
103103 if ( ! statusMessage ) {
104+ console . log (
105+ `Sending initial status message to channel ${ channel . id } .`
106+ ) ;
104107 statusMessage = await channel . send ( { embeds : [ embed ] } ) ;
105108 } else {
106109 await statusMessage . edit ( { embeds : [ embed ] } ) ;
@@ -133,14 +136,23 @@ function scheduleNext(startTime) {
133136
134137async function clearChannelMessages ( channel ) {
135138 try {
136- let fetched ;
137- do {
138- fetched = await channel . messages . fetch ( { limit : 100 } ) ;
139+ while ( true ) {
140+ const fetched = await channel . messages . fetch ( { limit : 100 } ) ;
139141 const deletable = fetched . filter ( ( msg ) => msg . deletable ) ;
142+
140143 if ( deletable . size > 0 ) {
144+ console . log (
145+ `Deleting ${ deletable . size } existing message(s) before sending status.`
146+ ) ;
141147 await channel . bulkDelete ( deletable , true ) ;
142148 }
143- } while ( fetched . size >= 2 ) ;
149+
150+ // Stop when fewer than 100 messages were fetched (end of history)
151+ // or when there is nothing left the bot is allowed to delete.
152+ if ( fetched . size < 100 || deletable . size === 0 ) {
153+ break ;
154+ }
155+ }
144156 console . log ( "Channel has been cleared." ) ;
145157 } catch ( err ) {
146158 console . error ( "Error while clearing channel:" , err ) ;
@@ -154,6 +166,9 @@ client.on("interactionCreate", async (interaction) => {
154166 if ( ! command ) return ;
155167
156168 try {
169+ console . log (
170+ `Executing command /${ interaction . commandName } by ${ interaction . user . tag } (${ interaction . user . id } )`
171+ ) ;
157172 await command . execute ( interaction ) ;
158173 } catch ( error ) {
159174 console . error ( "Command error:" , error ) ;
@@ -171,7 +186,7 @@ client.on("interactionCreate", async (interaction) => {
171186 }
172187} ) ;
173188
174- client . once ( "ready " , async ( ) => {
189+ client . once ( "clientReady " , async ( ) => {
175190 console . log ( `Logged in as ${ client . user . tag } ` ) ;
176191 channel = await client . channels . fetch ( process . env . DISCORD_CHANNEL_ID ) ;
177192
0 commit comments