error: these commands work for the first time, perfectly fine and the second+ time there is a delay in the whole bot until the second response is sent which crashes the slash commands, takes too long to respond to other normal commands, i have tried many things and still can't make this work, ill send all of the code below
#worker threads
15 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by OP
if(command === "azul" || command === "invert" || command === "sepia" || command === "pixel" || command === "posterize" || command === "blancoynegro" || command === "dither" || command === "contraste" || command === "oscuridad" || command === "brillo" || command === "rotate" || command === "mirrorh" || command === "mirrorv" || command === "mini" || command === "blur" || command === "verde" || command === "rojo" || command === "circulo"){
if (isWorking) {
return message.channel.send('Another image is being processed') //this is false by default above, this works fine isn't the issue
}
isWorking = true;
const processingMessage = await message.channel.send('Processing image...')
const { Worker } = require('worker_threads');
const worker = new Worker('./worker.js');
//here there is code to fetch the image on different ways ill just hide it cuz its too much
worker.postMessage({
image: imagexd,
command,
channelId: message.channel.id,
messageId: processingMessage.id,
});
//worker
worker.on('message', async (messageData) => {
console.log('Recieved')
const { channelId, messageId, buffer } = messageData;
if (buffer instanceof Uint8Array) {
const bufferAsBuffer = Buffer.from(buffer);
console.log('Looking good')
const attachment = new AttachmentBuilder(bufferAsBuffer, 'image.jpg');
try {
const canalsisi = await client.channels.fetch(channelId)
const mensajesisi = await canalsisi.messages.fetch(messageId)
isWorking = false;
console.log('it should have sent it already')
await mensajesisi.reply({ files: [attachment] });
} catch (error) {
console.log(error)
worker.terminate()
isWorking = false;
return;
}
}
worker.terminate()
isWorking = false;
});
worker.on('error', () => {
//error handling (there is no errors)
});
worker.on('exit', (code) => {
console.log('end')
worker.terminate()
isWorking = false;
});
//
}```
i already tried
- using and reusing a single worker by defining it above messageCreate
- doing that i also tried putting the worker.on outside the command, outside messageCreate and the const worker inside messageCreate and outside the command or only outside the messageCreate
- doing it with a single if (command)
its always the same issue
the console.log is a way to track the process, the "it should have sent it already" its out almost instantly but the message doesn't send, takes like 15 secs
and im not gonna share all of the worker as i alr know it has a fast response, idk what the issue is
worker.js end
.then((buffer) => {
console.log('sent')
parentPort.postMessage({
buffer,
messageId,
channelId,
});
parentPort.close();
})
.catch((err) => {
const customError = new Error(err.message);
customError.channelId = channelId;
throw customError;
})
});```
with and without parentport.close, worker.terminate, worker.unref is the same thing
the error again
command works first time, if you use another command while the image is processing sends the message Another image is being processed
if u use another random command it works fine
now if you use the command again it starts processing the image, takes longer than usual meanwhile the bot does not respond to other commands, slash commands crash and after like 15s it sends the image response and all of the acumulated responses of other commands
and by the console.log tracking the response shouldn't take that long and the bot just lags there idk why
ill go to sleep ill see this tomorrow
i have been since yesterday and today all day with this
lol
hi
hi
hi