Edit message on button click DJS14

Hey, I'm trying to make a slash command on my bot to fetch a list of users in my database. It'll work that way : /info pseudo:aznoob and will print a bunch of information game-related on the user. I know my query is working, now, my issue is with formatting. I would like to print each user individually with its own information within an embed, with 2 buttons : "previous" and "next". A good example of what I'm trying to do is Unbelievaboat with its leaderboard (see picture). I still question how I should do it though. I don't want to spam my database with queries, so the way I'm working right now is with a query that'll fetch all occurrence of my research and store it in an array. The bot will then build each embed within a for loop, and store it in an array. My code right now :
const queryResults = await db.query(query);
const embedList = [];
queryResults.rows.forEach((row) => {
embedList.push(buildEmbed.player(row));
});

const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`previousUserMatch`)
.setLabel("◀ Previous")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId("nextUserMatch")
.setLabel("Next ▶")
.setStyle(ButtonStyle.Primary)
);
return interaction.editReply({
embeds: [embedList[0]], // The hardcoded digit here must change on button clicks (+1 on "next" ; -1 on "previous")
});
const queryResults = await db.query(query);
const embedList = [];
queryResults.rows.forEach((row) => {
embedList.push(buildEmbed.player(row));
});

const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`previousUserMatch`)
.setLabel("◀ Previous")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId("nextUserMatch")
.setLabel("Next ▶")
.setStyle(ButtonStyle.Primary)
);
return interaction.editReply({
embeds: [embedList[0]], // The hardcoded digit here must change on button clicks (+1 on "next" ; -1 on "previous")
});
My main question is : how can I do to edit the message on button click ? Thanks for your help. Aznoob.
3 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
treble/luna
treble/luna2y ago
use collectors
d.js docs
d.js docs2y ago
guide Popular Topics: Collectors read more
Want results from more Discord servers?
Add your server