Discord how do I send a line from a text document and delete the used one afterwards?

hey as described in the title I want my bot to send a line from the text document (always the first) after the command and then delete the used line from the text document Please help I already have:

     else if (parts[0] == 'bot!send' || parts[0] == 'bot!Send') {

    let allowedRole = message.guild.roles.cache.get("name", "rolename");
    if (message.member.roles.cache.has('869893772673159208')) {
        const fs = require('fs');
        const path = "./Storage/123.txt";
        const content = fs.readFileSync(path, 'utf-8');
    } else {
        message.author.send('need the Right Role')

Pls need help Is very Important

Need help pls is very important

Hi @Davennix and welcome to the GitHub Community Forums.

Your last two messages are a bit unconstructive as they do not contribute to the discussion. Next time, please consider adding extra information to your question such as a clearer explanation or the programming language you’re working in to increase the chances of someone being able to answer your question.

From your code I’m guessing you’re using NodeJS. Note that your method reads the entire file, which might be fine as longs as the file isn’t too big.

You could split up the contents of the file by line by using the split() function with the newline character:

// or
content.split('\r\n') // sometimes on Windows, check what works

in order to obtain the first line of the file. You could then use a function like writeFileSync() in order to write the new file after stripping out the first line. Note that content is just a string containing the file contents and you can do any string operation on it.

1 Like