Overview
My Discord bot processes Roblox Lua files yet errors when reading file attachments. Below is updated sample code using recent Discord JS practices. Help fix this issue?
module.exports = {
command: 'obfuscate',
desc: 'Obfuscates a provided Lua or text file',
run(context, params, client) {
const noticeEmbed = new client.EmbedBuilder()
.setColor('#1A8FFF')
.setTitle('Lua File Obfuscator')
.setDescription('Please attach a valid .lua or .txt file for obfuscation.');
context.channel.send({ embeds: [noticeEmbed] });
const checkAuthor = m => m.author.id === context.author.id;
context.channel.awaitMessages({ filter: checkAuthor, max: 1 })
.then(collection => {
const attachment = collection.first()?.attachments.first();
if (!attachment) return;
require('fs').readFile(attachment.url, (error, content) => {
if (error) return;
const successEmbed = new client.EmbedBuilder()
.setColor('#FFAA00')
.setTitle('Obfuscation Complete')
.setDescription('Your file was successfully obfuscated.');
context.channel.send({ embeds: [successEmbed] });
context.channel.send('Obfuscated file content:', { files: [{ attachment: content }] });
});
});
}
};