Sending a text file from a folder with a Discord bot (discord.js)

Hello, I want to implement the feature in my Discord Bot to have a changelog that can be sent upon command. The information/updates in the changelog are on a .txt file in a folder called Storage.
How do I get that file to be sent? (Not as a attachement)

This is what I already have:

case ‘changelog’ : { ( … )

Hey @PervonHarke!

Node.js provides us with a native module called File Sytem (Docs), which will let you browse through files, thus reading and writing files. First, you should require the module, by adding const fs = require('fs') in your code. For your problem, you will be interested in using the readFileSync() method, which uses the path as first argument, and because you’re looking for reading .txt files, you should use the encoding, set it to 'utf-8'.

Here’s a simple example:

const fs = require('fs');

case 'changelog':
  const path = "./Storage/fileName.txt";
  const content = fs.readFileSync(path, 'utf-8');;

This should hopefully help you!


It worked,
thank you for your help and explanation of your solution!


Hey had the same problem has really helped me But Do you know maybe how I do it That always only one line is sent (Start from the top) and then the used deletes?