Home > Software design >  How can I display all of the information from a single column from MySQL?
How can I display all of the information from a single column from MySQL?

Time:08-01

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.

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);
}

CodePudding user response:

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: [embed]});
  • Related