1

How do I send a txt file in discord.js as an Attachment? Like this: enter image description here

I have tried the following code:

let content = nsOpts.Tcontent
fs.writeFileSync('./nosleep.txt', content)

let atc = new discord.MessageAttachment('nosleep.txt')

interaction.channel.send('here ya go,', { files: [atc, 'nosleep.txt', './nosleep.txt', 'attachment://nosleep.txt']})

But the bot only sends the message, not the file.

enter image description here

Thanks

Neev Jewalkar
  • 45
  • 1
  • 5

2 Answers2

1

This works for me.

let content = nsOpts.Tcontent;
let atc = new discord.MessageAttachment(Buffer.from(content), 'nosleep.txt');
interaction.channel.send({ files: [atc] });
Alex Ogre
  • 11
  • 1
0

Try this.

const fs = require('fs');
var atc = fs.readFileSync('./nosleep.txt', {"encoding": "utf-8"});
lizardpeter
  • 89
  • 1
  • 7