I made a bot with some help, I am a new dev so I don't know much. But when I do $redeemkey 12345678 it seems to go through (the bot replies back and console says "true") But one part doesn't work. The part where it deletes the argument from the txt file. Any help is appreciated here is my script:
if (command === '$redeemkey') {
const fs = require('fs')
const haspath = `whitelisted/${message.author.id}.txt`;
if (fs.existsSync(haspath)) return message.reply({
embeds: [
new MessageEmbed()
.setColor('RED')
.setDescription(`You're already whitelisted!`)
]
});
fs.readFile('notredeemed.txt', function (err, data) {
if (data.toString().match(new RegExp(`^${args[0]}$`, "m"))) {
const match = new RegExp(`(\n|^)${args[0]}(\r|$)`)
const newFile = data.toString().replace(match, '')
fs.writeFile('notredeemed.txt', newFile, "utf8", function (err) {
if (err) return console.log(err)
console.log("true")
})
}
})
}
Thanks!