jowsey / discord.js-menu

💬 Create Discord.js embed-menus, with customizable reactions and unlimited pages.
https://npm.im/discord.js-menu
MIT License
120 stars 19 forks source link

Not exactly an issue. #21

Closed AlgorithmicPolicyIndex closed 3 years ago

AlgorithmicPolicyIndex commented 3 years ago

This isn't an issue, more or less just a question on how I could do something.

MessageEmbed Var

let Pages = new MessageEmbed({
  title: 'Your created Tickets | Max Pages = 5 / 50 Tickets Max',
});

Function For my Loop

function menuContent(off) {
  if(!off){off = 0}
  con.query(`SELECT * FROM ticket_data WHERE User_ID = '${message.author.id}' LIMIT 10 OFFSET ${off}`, (err, rows) => {
    if (err) throw err;
    let status;

    for (i = 0; i < rows.length; i++) {
      if (rows[i].Approval_Status === 1) { status = "Approved" } else {  status = "\nNot Approved"}
      Pages.addField(`Ticket ${i+1} (${rows[i].Ticket_ID})`, `**Approved Status:** ${status}`, true);
    }
  });
}

My entire Sub command

I'm creating a list of pages from my database, but I have to loop through it before adding the field. I've been trying to test how I could run the function based on the page you're on. So page one, it lists 0-9 from my DB, Page two 10-19 and so on. I haven't found a way to use it in the menu or a way to use it in the .on('pageChange')

Is it possible to run my function based on the page? so it showed like this Rather than this

Thanks for reading my "issue"

AlgorithmicPolicyIndex commented 3 years ago

Sorry for the more of a time waster. https://gyazo.com/ff33ef4c605af713301f04472eb7cde8

I just got it working. I moved the menu into the function, then called the function. It works now, for the first page at least. I'll need to figure out how to update the second page and so on

Okay, so having put the menu in the function was kind of a mistake.

I can't update the offset from inside it, without making my code very cluttered with con.query(...) but it seems to be my only fix for now. I'll be commeting out my current function, just in case I do find a fix or if I'm replied with one. image