mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
setnewbot may fix it ig
This commit is contained in:
parent
aab744f1eb
commit
6ea46cff2a
2 changed files with 12 additions and 4 deletions
7
bot.js
7
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);
|
||||
});
|
||||
|
||||
|
|
9
index.js
9
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue