Saving chat logs from Discord using Discord.js

I encountered an issue with a discord.js ticket transcript command. The problem arises when using the command to generate a .txt file and send it to the channel, as intended. However, the file ends up being saved locally, which is not the desired outcome.

Here is the code responsible for creating the txt file and sending it:

fs.writeFileSync(`${message.channel.name}.txt`, content.join('\n'), err => { if (err) throw err });

doneEmbed(message, lang.ticket.transcript.replace('{name}', `${message.channel.name}.txt`));
return message.channel.send(new MessageAttachment(`${message.channel.name}.txt`, `${message.channel.name}.txt`));

The doneEmbed function is used for embedding purposes, here is a brief overview:

//Emoji file
const e = require('../../data/config/emojis.json');

//Embed
module.exports.doneEmbed = function doneEmbed(message, desc) {
    let embed = new MessageEmbed()
        .setDescription(e.done + desc)
        .setColor(c.done)
    message.channel.send(embed);
}

Below is the file structure where the transcripts are incorrectly saved (🎫 | exstare.txt & 🎫 | test.txt):

https://i.sstatic.net/YeQJh.png

Any assistance would be greatly appreciated!

Answer â„–1

To ensure successful attachment, your application must save the file before sending it. It is a necessary step in order to send files effectively.

However, there is a simple solution to prevent cluttering your project folder with unnecessary files. After sending the file as an attachment with your Discord bot, you can simply delete the file afterwards. For guidance on how to delete a file using FileSystem, check out this website for helpful examples:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Provide users with the option to select a specific destination for saving their file

In the midst of my spring MVC project, I find myself in need of implementing a file path chooser for users. The goal is to allow users to select a specific location where they can save their files, such as C:\testlocation\sublocation... Despite r ...

How can I convert a list of checkboxes, generated by ng-repeat, into multiple columns?

Here is the HTML code snippet: <div class="checkbox"> <label> <input type="checkbox" ng-model="selectedAll.value" ng-click="checkAll()" />Check All </label> </div> <div class="checkbox" ng-repeat="carType i ...

Executing a javascript file inside a jade document

I need help incorporating a JavaScript file into my Jade file so that it runs every time the page is accessed. How can I achieve this? Here is my current code snippet: doctype html html head title= title body h2 Bus Driver Locati ...

Struggling with synchronicity in javascript(node.js) and seeking assistance

I am faced with a challenge in my express.js app where I need to execute a script on the server, followed by running a couple of functions to derive some values. The process should be sequential, but I am running into issues as JavaScript seems to move on ...

Unable to show the same error message in multiple locations using identical code

I am facing an issue where error messages are not displaying for an empty input field, while they work perfectly fine for a textarea. The if statement for the inputName seems to be working, but the else statement is not being triggered. What could be causi ...

What is the process for validating the CSS background-image URL using Javascript?

The concept here is to verify the URL of the CSS element's id (.boot). If the URL matches, which it does, then it should display "hello world." However, despite everything seeming correct, the expected behavior is not occurring, and the reason behind ...

Display input checkboxes using ng-repeat based on dynamically changing conditions

My goal is to dynamically display checkboxes with labels based on a conditional flag. The label values are defined as: $scope.listA = [ { name : "Sample 1" }, { name : "Sample 2" } ]; $scope.listB = [ { name : "Result 1" } ...

Practice window.performance.getEntriesByType with a mock function

I am facing an issue in my component where I need to check if the page is reloaded and redirect to another page. Here is the code snippet I am using: useEffect(() => { //this will prevent users from accidentally refreshing / closing tab window.o ...

"Upon loading an mtl file in three.js, the result appears

I'm encountering an issue while attempting to incorporate a .obj level into my program as it appears black when rendered. The associated .mtl file necessitates multiple images spread throughout, leaving no untextured spaces. Strangely, the same object ...

Protect database entries from cross-site scripting attacks

I have a project in progress where I am developing an application that extracts text from tweets, saves it to the database, and then presents it on the browser. I am currently concerned about potential security risks if the text contains PHP or HTML tags. ...

Providing secure access to Apostrophe-CMS S3 assets and attachments via HTTPS

Currently, I am utilizing Amazon S3 to deliver both my static assets and user uploads within the context of apostrophe-cms. While my site is loading via https, all of my assets appear to be loading using http. I have set up a cloudfront distribution at th ...

Using the .map function on JSON data with and without a parent element in JavaScript

In my current project, I am working on a React + Rails application. For handling JSON data, I typically use the default jbuilder in Rails. However, following the recommendations from the react-rails official documentation, I started adding a root node to m ...

Is there a way to incorporate unique shapes into mxGraph?

What is the process for including custom shapes in mxgraph? Image Representation of Shapes Check out these BPM shapes ...

The menu includes a "scroll to #href" feature, however, it does not support links that open in a new tab (target blank)

I have encountered an issue with my website's navbar, which has a scroll-to-link function as it is a one-page site. Recently, I tried to add a new link to the menu that directs users to an external page (not within the same page). However, when I cl ...

transferring information to a PHP page using JavaScript without using AJAX requests or form submissions

I am currently working on a PHP page where I receive POST data using some functions, without relying on AJAX for page refresh. At the moment, I have a form that includes hidden fields holding dynamic data, which is then sent using JS like this: document.m ...

Sending the ID of a mapped button to a component

I need help with my React mapping function that displays a series of cards, each with its own button to open up a dialog box. Right now, I'm struggling to pass the unique ID from each object to the correct dialog box. Instead, all IDs are being passed ...

I keep encountering an error with the Next.js Image component, even though I have properly included the src prop

By passing the src prop to the UserCard component, I am encountering the following error message. Error Unhandled Runtime Error Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` comp ...

Adding JSON data to a MySQL column in JSON format with the help of NodeJS

I currently have a MySQL table set up with the following specifications: CREATE TABLE `WorkOrders` ( `workorder_id` int(11) NOT NULL AUTO_INCREMENT, `intertype_id` int(11) NOT NULL, `equipment_id` int(11) NOT NULL, `reason_id` int(11) NOT NULL ...

The quantity of elements stays constant even after adding to them using Javascript

I have implemented a notes list feature that allows users to add notes using an input field. Beneath the notes list ul, there is a message showing the total number of notes: $('li').length. However, I encountered an issue where the count of not ...

How can formatted text (such as bold or red text) be stored in MongoDB?

Can we store the text as bold or in red color within mongodb? For instance, I have this bold Text Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type ...