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

Determine if every object in the array contains a specific key value pair

I am dealing with the following JSON data: { records:{ data:{ current:{ records:{ '2years':[{a:1, b:2, flag:true}, {a:2, b:4}, ...

Utilizing a range input (slider) to extract data of importance

When dynamically adding a slider to a page using a specific string, like the one shown below: "<input type=\"range\" name=\"aName\" min=\"1\" max=\"9\"/>"; After appending it to the page with pure JavaScript, ...

eliminate the firebase firestore query using onSnapshot

Seeking assistance with the following code snippet: firebase.firestore() .collection("chatrooms") .doc(`${chatId}`) .collection(`${chatId}`) .orderBy("timestamp") .limit(50).onSnapshot((snapshot) => { //performing oper ...

Issue: It seems like there is an error with using functions as a React child. Uncertain about the exact location

This specific issue is one of the two errors I have come across in the same application referenced in my previous inquiry. The first error encountered is as follows: Warning: Functions are not valid as a React child. This may occur if you mistakenly return ...

What is the best way to display an image along with a description using Firebase and next.js?

I am currently utilizing Firebase 9 and Next.js 13 to develop a CRUD application. I am facing an issue where the images associated with a post are not correctly linked to the post ID. Furthermore, I need guidance on how to display these images in other com ...

Issues arising while passing a parameter to a Node.js module

I've been struggling with passing a variable to a module. In my node.js setup, I have the following structure: The main node.js server (server.js): // modules ================================================= var express = require('expr ...

Performing a reverse image search request using Javascript/AJAX to query Google

I have been attempting to perform a reverse image search request using AJAX, but I keep receiving 302 errors. After checking the Firebug console, I discovered that the response header from Google contains a URL linking me to the results. However, I am unsu ...

Asynchronously retrieving results in MongoDB

My task involves fetching all users from the users collection. app.post('/login', function(req,res,next){ users = self._db.get('users', {}) }) Below is the function in my database class: this.get = function( col, opt ) { ...

Creating personalized validation for an AJAX popup in the MVC framework

In my MVC project, I am trying to implement AJAX popup with custom validation. I have created a CustomValidator class and overridden the IsValid() method. However, I am facing an issue where the custom validations are not rendering correctly within the pop ...

What is the best way to automatically add a date and timestamp to every new entry?

I am currently working on a project that utilizes AngularJS and Ionic frameworks. The main feature of the project will involve users inputting data to create a list, and allowing any user to comment on each item in the list. One challenge I have encounter ...

The Angular @HostListener beforeunload Event is a powerful way to handle

I've implemented the following code snippet in my main app.component.ts file within my Angular 17 project: @HostListener("window:beforeunload", ["$event"]) onTabClose($event: BeforeUnloadEvent) { $event.preventDefault(); ...

Exploring AngularJS and Jasmine: Testing a controller function that interacts with a service via $http

I encountered an issue while testing a controller that relies on a service. The problem arises because the service is currently set to null in order to focus solely on testing the controller. The current test setup is failing due to the BoardService being ...

Listener for 'timeupdate' event on video doesn't retain values

My html5 video event listener is designed to pause the video at a specific time while the user participates in a quiz. The first 'lesson' works fine, and the second video also appears to add the listener with the correct pause time. However, when ...

Transform a log file into a JSON structure

In my log file titled request.log, the following entries are present: [2022-06-30T09:56:40.146Z] ### POST https://test.csdf/auth/send_otp { "method": "POST", "headers": { "User-Agent": "testing&q ...

Stop the selection of text within rt tags (furigana)

I love incorporating ruby annotation to include furigana above Japanese characters: <ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby> However, when attemp ...

Guide on integrating a jQuery method for validating a value using regular expressions

I'm currently using the Jquery validation plugin to validate form fields. One of the fields I am validating is for academic years, which should be in the format of 2013-2014. To achieve this validation, I have created a custom Jquery method as shown b ...

Looking to display several charts on a single page with varying datasets?

I have successfully integrated a doughnut chart plugin into my website. However, I would like to display multiple charts on the same page with different data sets. Below is the code snippet for the current chart being used: This is the chart I am using & ...

Closing a live search box by tapping away from it

The link I found as the best example for this topic is: http://www.example.com In the example provided, if you enter a keyword in the search field, suggestions will drop down. I have implemented this code but would like to make a slight modification. I w ...

Encountering issues with verifying login credentials in Angular 2

Greetings! I have designed a login page where the user will be logged in if the response is successful, otherwise an error message will be displayed. Below is the JSON data with email and password fields: { Email": "<a href="/cdn-cgi/l/email-protect ...

Tips for configuring ejs data within the data attribute and processing it using client-side JavaScript

My aim is to transfer leaderboard information from the server to the client-side JavaScript. This is the code on my server side: const leaderboard = [[dog,cat],[car,bus],[foo,bar]] const toJson = JSON.stringify(leaderboard) res.render('gam ...