Reading txt datei and Send one Line and After deletet

Hey as I said before I have a problem When I enter my command the whole txt file is sent and I do not know how to change it please help (Discord bot)

else if (parts[0] == ‘!bot’ || parts[0] == ‘!bot’) {

 const fs = require('fs');
 const path = "./Storage/BOT.txt";
 const content = fs.readFileSync(path, 'utf-8');

    message.author.send('**Here**')
    message.author.send(content)

Hi @Davennix,

From reading this and your other post, it sounds like you want the following behaviour:

  • When a user sends ‘!bot’ message:
    • Read the BOT.txt file
    • Take the top/first line and send it as a reply
    • Delete the top/first line from the file

Is that right?

If so, here is a useful link I found:

Hi
Thanks for the Answer i try the Code but dont work for me but yea i try to do that:

  • When a user sends ‘!bot’ message:
    • Read the BOT.txt file
    • Take the top/first line and send it as a reply
    • Delete the top/first line from the file

Ok, so it would be good if you showed us what you tried, and maybe other resources that you’ve looked at. Really happy to help but I don’t want to just write the solution for you :slight_smile:

Have you thought about how to achieve these two points with JavaScript? What functions have you considered?

  • Take the top/first line and send it as a reply
  • Delete the top/first line from the file

As others have pointed out there isn’t much information to go on most important (I think) is “what are you trying to do”? It might turn out that you have to use this file, it may turn out that any other format would work better. What does it do when there are no more lines in the file?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.