Creating a Discord Bot: Building an Embed Table/List with Segmented Sections

Currently in the process of learning Javascript and venturing into discord.js, I'm fully aware that the code I am working with is not up to par and requires some serious refinements.

The main objective here is to split up the arguments of a command and display them as separate lines in an embed.

For instance, if I were to execute:

!results "Result 1" "Result 2" "Result 3"
, the desired output would be formatted like a table within an embed:

RESULTS:
Result 1
Result 2
Result 3

However, my current output ends up looking like this:

View the discord screenshot here

I've tried multiple approaches after scouring Google for solutions, but it seems like the correct solution continues to elude me.

const { RichEmbed } = require("discord.js");

module.exports = {
    name: "results",
    category: "info",
    description: "posts results in embed",
    usage: "<mention, id>",
    run: async (client, message, args) => {
            if (message.deletable) message.delete();

        let [result1, result2, result3, result4, result5, result6, result7] = args;

        if (!args[0])
            return message.channel.send("Please provide Result 1.").then(m => m.delete(5000));
        // Rest of validation checks...

        const channel = message.guild.channels.find(c => c.name === "cards")

        if (!channel)
                return message.channel.send("Couldn't find a `#cards` channel").then(m => m.delete(5000));

        const embed = new RichEmbed()
            .setColor("RANDOM")
            .setTimestamp()
            .setAuthor("Posted by GM:", (message.author.username, message.author.displayAvatarURL))
            .setTitle("**TestTitle**")
            .setFooter(message.guild.name, message.guild.iconURL)
            .setDescription(`**__Results!__**`)
            // Adjusted fields...

        return channel.send(embed);
    }
}

UPDATE: Some progress has been made, featuring the latest version of the code producing this output:

Check out the updated image here

Answer №1

When adding a new field, make sure to include both a title and a value. Simply providing a value without a title can cause confusion. It's best to utilize the description field and organize your content using new lines for clarity. Keep in mind that the description field has a limit of only 2048 characters.

If you need guidance on creating embeds, check out this helpful resource:

Answer №2

To handle the arguments effectively, it's recommended to introduce a new delimiter, such as a comma or similar punctuation mark.

    const prefix = "!";
    if (message.author.bot) return;  // stop processing if author is a bot
    if (!message.content.startsWith(prefix)) return;  // stop processing if message is not a bot command

    const commandBody = message.content.slice(prefix.length);
    const args = commandBody.split(' ');
    const command = args.shift().toLowerCase();

    if(command === "ping"){
        message.channel.send("Hello");
    }
    if(command === "test"){
        message.channel.send("it is a good day for testing!");
        if (args.length > 0) {
            message.channel.send("Hello " + args[0]);
        }
    }

To implement this change, replace the .split(' ') with something like a comma: .split(',')

For example, when the user inputs !test,myName the bot would respond with:

it is a good dat for testing
Hello myName

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

Tips for passing a page as an argument in the function parameter of the page.evaluate() method?

I keep running into this issue when I pass the page as an argument: TypeError: Converting circular structure to JSON --> commencing at object with constructor 'BrowserContext' | property '_browser' -> object with const ...

Guide on choosing the filename for downloads in Front-End applications

UPDATE: Creating a Blob from a base64 string in JavaScript I'm currently working on a feature where a user can click a button to download a file from its DataURL. However, due to Chrome restrictions on building <a> links, I encountered an err ...

The terser-webpack-plugin and uglifyjs-webpack-plugin are both powerful tools for optimizing

WebPack 4 now utilizes the terser-webpack-plugin in production mode or when the -p argument is specified, which essentially means including --optimize-minimize --define process.env.NODE_ENV="production". This plugin is responsible for minimizing ...

Checking for the Existence of a Database Table in HTML5 Local Storage

Upon each visit to my page, I automatically generate a few local database tables if they do not already exist. Subsequently, I retrieve records from the Actual Database and insert them into these newly created local tables. I am wondering if there is a me ...

Ensure the Firebase real-time database in Javascript purges the active session upon tab or browser closure

I need to implement a feature in my Firebase real-time database project using JavaScript where the current session is logged out automatically after closing the tab or browser. When I log in with my email and password, if I copy the URL and paste it into ...

Improving Zen Coding to integrate with JavaScript files on Sublime Text2

Sublime Text2 is hands down my go-to editor, except for one minor hiccup - the Zen Coding plugin only works with CSS and HTML files. There are plenty of times where I'd love to use Zen Coding with JavaScript or other file types, like incorporating HTM ...

Warning: Unhandled promise rejection - Type error encountered when trying to access property

While working on a simple login validation, I encountered an issue when deliberately inputting an incorrect email in the login post method via postman. UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'password' of null at C:&b ...

Is it possible to determine if an AJAX request is still ongoing when a user returns to a webpage using jQuery or JavaScript?

Users on a specific page must click a 'generate' button to create details for a record. When the button is clicked, an ajax request is triggered to generate the record, which may take some time. $("#generate_record_button").on("cl ...

Prevent form submission using jQuery based on ajax response, or allow it to submit otherwise

After setting up some jQuery code to handle form submission, the functionality is working well when certain conditions are met. However, I am facing a challenge in allowing the form to be submitted if the response received does not match specific criteria. ...

Are there any testing frameworks available for JavaScript that are similar to Junit and specifically designed for testing object-oriented JavaScript within Node

What are some recommended methods for testing object-oriented JavaScript in Node.js? For instance, let's consider the following Cat.js class: function Cat(age, name) { this.name = name || null; this.age = age || null; } Cat.prototype.getAge ...

Setting URL parameters dynamically to the action attribute of a form using JavaScript code

I'm having trouble posting Form data to my Server. I am dynamically setting the element and its URL parameters for the action attribute, but it seems like it's not recognizing those attributes. Can you help me figure out what I'm doing wrong ...

Visualizing connections between elements using SVG from JSON data files

As a newcomer to D3, I am facing challenges in visualizing my json file. My task involves plotting the locations (sites) as circles with their radius determined by the "amount" value. The concept of working with nodes and links is causing me great confusio ...

The touch event doesn't seem to be functioning properly on the div element, but it works perfectly on the window element

I have a dilemma that's been puzzling me lately. I'm trying to append a touchevent to a div, but my current method doesn't seem to be working. Here's what I've tried: $("#superContainer").bind('touchstart', function(even ...

Why does the second JavaScript form validation not function correctly when compared to the first?

Here is a form that I have created: <form action="next.html" id="userInput" method="post" onsubmit="return validate();"> Age: <input type="text" name="age" id="age"/> function validate() { var age = document. ...

Error message: The Node.js filtered LS command is missing a ")" after the argument list

I've been working on the learnyounode workshop and I'm stuck on a code issue. After running it through jslint, I received this feedback: Expected ')' to match '(' from line 6 but instead saw '{'. Oddly enough, line ...

Event with no refresh required

When using chat scripts, new lines can be added without reloading the page. The user's availability status can change without a postback. Similar to Facebook, a new comment can be added without reloading the page. How can an event be triggered in ASP. ...

Angular Date Filtering to Show dd-mm-yyyy Format

I am having trouble filtering the date correctly in my controller. My desired date format is Thu Mar 31 2016 05:05:00 GMT-0400 (EDT). However, when I use the code mentioned above, the results show up as 03-31-2016. This is the code snippet from my contr ...

Adding Bootstrap to container-specific styling in SCSS

I am currently in the process of upgrading to the most recent version of reactstrap & Bootstrap. Previously, I had reactstrap in my package.json file and downloaded Bootstrap SCSS in my client/src/styles/bootstrap directory. Now, my updated package.json c ...

Troubleshooting problems in transferring JSON data between a React application and a Spring Boot service running locally

Running a local Springboot server, accessing it locally in the browser returns a properly formatted JSON object. However, encountering issues when trying to fetch this JSON object from a React application running on node locally. Managed to overcome CORs h ...

The functionality of the Toastr "options" seems to be malfunctioning

I am having some trouble with my Toastr notification messages. While the message does display, I seem to be unable to make use of any options that I set. Despite specifying some options, they do not seem to work as intended. $('#editButton').c ...