From cd5cfb20a429bafc0521758e6a0d50de675f3b54 Mon Sep 17 00:00:00 2001 From: MrMasrozYTLIVE <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sat, 8 Jun 2024 23:36:00 +0300 Subject: [PATCH] Replaced 'setTimeOut' with bot.on('onBotJoinRoom', () => {}); for sending ON_READY_MESSAGE to the chat --- chatBot/bot.js | 7 +------ chatBot/includes/client.js | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/chatBot/bot.js b/chatBot/bot.js index e23e5f1..4a3e775 100644 --- a/chatBot/bot.js +++ b/chatBot/bot.js @@ -61,15 +61,10 @@ loadCommands().then(commands => { bot.on('onBotJoinRoom', () => { console.log("Bot is ready!"); + bot.sendMessage(process.env.ON_READY_MESSAGE); }); bot.joinChatRoom(); - - // Wait for 2 seconds for the bot to connect - setTimeout(() => { - // Send a message - bot.sendMessage(process.env.ON_READY_MESSAGE); - }, 2000); // Adjust the delay as necessary }).catch(error => { console.error('Error loading commands:', error); }); diff --git a/chatBot/includes/client.js b/chatBot/includes/client.js index e20c13a..7d61fbd 100644 --- a/chatBot/includes/client.js +++ b/chatBot/includes/client.js @@ -27,8 +27,8 @@ class Client extends EventEmitter { joinChatRoom() { this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true}); this.discovery.flushed().then(() => { - this.emit('onBotJoinRoom') console.log(`Bot ${this.botName} joined the chat room.`); + this.emit('onBotJoinRoom'); }); }