Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I display all of the information from a single column from MySQL?

I am programming a discord bot and am fairly new with MySQL. I’ve tried to do this myself, but maybe I’m missing something.

I want to display all of the information from a specific column for all rows in a table. It’ll do that, however, my method has so far proven to send three separate discord messages, and I would like it only to send one.

I know that i++ will increment, but I didn’t think it’d increment into three messages. Not too sure what to do about this, as I’m not an expert.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Many thanks in advance!!

const [check1, check1d, check1e] = await pool.query("SELECT `TeamName` FROM `performancetracker`.`queue`");

var i;

for (i = 0; i < check1.length; [i++]) {

  const result = (`${check1 [i].TeamName}`)

  const embed = new MessageEmbed()
    .setTitle("Test Name")
    .setDescription(`Test Description`)
    .addField('Team Name:', `${result}`, true)
    .setTimestamp()
    message.channel.send(embed);
}

>Solution :

The problem is that you’re using message.channel.send()on every loop, thus the message will be sent again. You need to use it after the loop is done.

You also need to define the embed before the loop and only use .addField() inside of it.

Like this:

   var i;

  const embed = new MessageEmbed()
  .setTitle("Test Name")
  .setDescription(`Test Description`)
  .setTimestamp()

  for (i = 0; i < check1.length; [i++]) {

   const result = (`${check1 [i].TeamName}`)
   embed.addField('Team Name:', `${result}`, true)
  }

  message.channel.send({embeds: });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading