From 6ea46cff2ad2dc0c88400346341c5fa7f308b143 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 27 Nov 2022 12:46:19 +0700 Subject: [PATCH] setnewbot may fix it ig --- bot.js | 7 +++++-- index.js | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bot.js b/bot.js index 9ef04c6..6b47105 100644 --- a/bot.js +++ b/bot.js @@ -21,11 +21,12 @@ const mineflayer = require('mineflayer'); * @param {object} server the server object used in the config * @param {object} config the config file * @param {Function} getBots get bots function in index.js + * @param {Function} setNewBot ig real * @param {Class} dcclient discord client * @param {object} rl readline. * @return {object} the bot object */ -async function createBot(server, config, getBots, dcclient, rl) { +async function createBot(server, config, getBots, setNewBot, dcclient, rl) { const bot = new EventEmitter(); bot.options = { username: !server.kaboom ? @@ -54,6 +55,8 @@ async function createBot(server, config, getBots, dcclient, rl) { await sleep(200); + setNewBot(bot.options.host, bot); + await loadPlugins(bot, dcclient, config, rl); const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]); @@ -156,7 +159,7 @@ async function createBot(server, config, getBots, dcclient, rl) { setTimeout(() => { bot.end(); - createBot(server, config, getBots, dcclient, rl); + createBot(server, config, getBots, setNewBot, dcclient, rl); }, timeout); }); diff --git a/index.js b/index.js index 490984c..22246bd 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ const readline = require('node:readline'); const {stdin: input, stdout: output} = require('node:process'); const rl = readline.createInterface({input, output}); @@ -12,14 +13,18 @@ const dcclient = new Client({ intents, }); -const bots = []; +let bots = []; dcclient.on('ready', () => { config.servers.forEach(async (server) => { const getBots = () => bots; + const setNewBot = (server, bot) => { + bots = bots.filter((eachBot) => eachBot !== server); + bots.push(bot); + }; // await is important cuz the function is async // VVVVV - const bot = await createBot(server, config, getBots, dcclient, rl); + const bot = await createBot(server, config, getBots, setNewBot, dcclient, rl); bots.push(bot); }); });