When a user sends a fur file with “$fur2mp3”,
the bot has to download it to the local repository,
convert it through an external batch script,
and send the converted file to a channel.
but an asynchronous problem causes the bot to run the script in the middle of downloading the sent file so display it as an empty file…
So I tried to solve the problem using await and async, but every time I do, I get this error
C:UsersUserDocumentsDiscord-CommandLine-1.0.1node_modulesdiscord.jssrcrestRequestHandler.js:154
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:UsersUserDocumentsDiscord-CommandLine-1.0.1node_modulesdiscord.jssrcrestRequestHandler.js:154:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (C:UsersUserDocumentsDiscord-CommandLine-1.0.1node_modulesdiscord.jssrcrestRequestHandler.js:39:14) {
method: 'post',
path: '/channels/(hidden channel ID)/messages',
code: 50006,
httpStatus: 400
}
Node.js v20.16.0
The script is
commands.add('fur2mp3', async () => {
const filePath = 'buffer_furrendering.txt';
if (fs.existsSync(filePath)) {
msg.channel.send('Another file is being processed! Please wait!');
return;
}
if(msg.attachments.first()){//checks if an attachment is sent
//if(msg.attachments.first().filename === `fur`){
msg.channel.send('Uploading...');
await download(msg.attachments.first().url);
msg.channel.send('Uploaded!');
//msg.channel.send('d');
msg.channel.send('Current Furnace Tracker Version : 0.6.5nConverting started!');
msg.channel.startTyping();
exec('fur2wav.bat buffer_furinput.fur', (error, stdout, stderr) => {
if (error) {
msg.channel.send(`Error during conversion: ${stderr}`);
console.error(`Conversion error: ${stderr}`);
return;
}
fs.readFile('buffer_fur2wavmsg.txt', 'utf8', (err, gwav) => {
if (err) {
msg.channel.send('Error reading conversion message.');
console.error(err);
return;
}
console.log('gwav content:', gwav); // Log content
if (gwav.trim()) { // Ensure gwav is not empty
} else {
msg.channel.send('The conversion did not produce any output.');
}
msg.channel.send({ files: ["furoutput.mp3"] });
});
});
} //msg.channel. // 파이 이름 ㅍbuffer_furinput.fur'
else { msg.channel.send('Send your file with this command!');
return; }
});
I need to remove await and async from here to proceed without error (though of course nothing is converted)
is there a mistake?