0

It's my first time working with a database and I ran into a problem. I want to make an embed with information from a database. The Bot can only read those informations and not change anything. I set up the Bot with the Database using npm mysql. Now I got my Database connection ready and the embed ready but I don't really know how to combine those two things. In the Value fields from the embed should the information from the database go. For example, in the database there's a column with male players, and because they change throughout the day I want to make an embed that shows exactly how many male players there are when somebody types in the command info.

Database Connection Code (everything is private for a reason):

    const connection = mysql.createConnection({
        host     : 'private',
        port     : 'private',
        user     : 'private',
        password : 'private',
        database : 'private',
        charset  : 'private'
      });


    connection.connect()

My Code for the embed (in the value fields should the information from the database go):


    if(message.content.startsWith(prefix + 'info')) {
         
        const sembed = new Discord.MessageEmbed()

        .setTitle('Info:')
        .setThumbnail('png')
        .setColor('GOLD')
        .addFields(
            {name: 'Players:', value: ''},
            {name: '👨🏻', value: '', inline: true},
            {name: '👩🏻', inline: true},
            {name: '👧🏻', value: '', inline: true},
        )
        .setTimestamp()

        message.channel.send({embeds: [sembed]})
      }



3
  • 1
    why you put every value as private ? Commented Oct 22, 2021 at 18:03
  • 1
    Did you notice that there's and extra quote (')? You can see where with syntax highlighting Commented Oct 22, 2021 at 18:08
  • Changed that in the code, ty Commented Oct 22, 2021 at 18:09

1 Answer 1

1

For database connection use those line of code with proper value.

const connection = mysql.createConnection({
    host     : 'localhost',
    port     : 'your my sql port',
    user     : 'my sql username',
    password : 'user password',
    database : 'database name',
    charset  : 'utf8mb4'
  });

connection.connect()

Hope that may be help to you any query ask me.

Sign up to request clarification or add additional context in comments.

7 Comments

I did that but I put everything in private for obvious reasons. The problem I got is not with the database connection itself but with filling the values in the embed because there should the information from the database go. For example, in the database there's a column with male players, and because they change throughout the day I want to make an embed that shows exactly how many male players there are when somebody types in the command info
For that you have to store all info then you have to filter them by male or female category .
I'm so sorry but i have no idea what you mean or what i should do. Like i said that's my first time working with a database
then you have to learn sql first . for that you can go w3schools.com
If you mean the database everything is set up there. Everything is filterd and i just need to become the information in the embed
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.