Answer the question
In order to leave comments, you need to log in
Thread worker + discord.js not working how to solve [nodejs] problem?
Error while running: TypeError [Error]: Cannot use 'in' operator to search for 'SHARDS' in world
index.js
const { Worker } = require('worker_threads')
function runService(workerData) {
return new Promise((resolve, reject) => {
const worker = new Worker('./core/core.js', { workerData });
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
})
})
}
async function run() {
const result = await runService('world')
console.log(result);
}
run().catch(err => console.error(err))
const { workerData, parentPort } = require('worker_threads')
const token = require('../configs/token.json')
const prefixes = require('../configs/prefixes.json')
const fs = require('fs')
const Discord = require('discord.js')
const YWS = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] })
YWS.login(token.token).then(console.log(`${prefixes.core} \x1b[32mClient login successful!\x1b[0m`))
const eventFiles = fs.readdirSync('./core/events').filter(file => file.endsWith('.js'));
console.log(`${prefixes.core} Loaded events: \x1b[32m${eventFiles.length}\x1b[0m`)
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
var res = YWS.once(event.name, (...args) => event.execute(...args, YWS));
} else {
var res = YWS.on(event.name, (...args) => event.execute(...args, YWS));
}
}
parentPort.postMessage({ hello: workerData, test: res })
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question