Auric
Auric
SIASapphire - Imagine a framework
Created by Auric on 2/4/2023 in #sapphire-support
How can I effectively use the `PaginatedMessage` function?
const queue = this.container.client.player.getQueue(interaction.guild!);

if (!queue) return interaction.reply({ content: `${this.container.client.dev.error} | I am not in a voice channel`, ephemeral: true });
if (!queue.tracks || !queue.current)
return interaction.reply({ content: `${this.container.client.dev.error} | There is no queue`, ephemeral: true });

await interaction.deferReply();

const { title, url } = queue.current;
let pagesNum = Math.ceil(queue.tracks.length / 5);
if (pagesNum === 0) pagesNum = 1;

const tracks: any = [];
for (let i = 0; i < queue.tracks.length; i++) {
const song = queue.tracks[i];
tracks.push(
`**${i + 1})** [${song.title}](${song.url})
`
);
}

const pages: any = [];
for (let i = 0; i < pagesNum; i++) {
const str = tracks.slice(i * 5, i * 5 + 5).join('');
const embed = new EmbedBuilder()
.setAuthor({
name: `Queue for ${interaction.guild!.name}`,
iconURL: interaction.guild?.iconURL()?.toString()
})
.setColor('Red')
.setDescription(`**Now Playing:** [${title}](${url})\n\n**Queue:** ${str === '' ? '*No more queued songs*' : `\n${str}`}`)
.setFooter({
text: `${queue.tracks.length} song(s) in queue`
});

pages.push(embed);
}

const paginatedMessage = new PaginatedMessage().addPageEmbed(pages[0]);
if (pagesNum > 1) paginatedMessage.addPageBuilder((builder) => builder.setEmbeds(pages));

return paginatedMessage.run(interaction, interaction.user);
const queue = this.container.client.player.getQueue(interaction.guild!);

if (!queue) return interaction.reply({ content: `${this.container.client.dev.error} | I am not in a voice channel`, ephemeral: true });
if (!queue.tracks || !queue.current)
return interaction.reply({ content: `${this.container.client.dev.error} | There is no queue`, ephemeral: true });

await interaction.deferReply();

const { title, url } = queue.current;
let pagesNum = Math.ceil(queue.tracks.length / 5);
if (pagesNum === 0) pagesNum = 1;

const tracks: any = [];
for (let i = 0; i < queue.tracks.length; i++) {
const song = queue.tracks[i];
tracks.push(
`**${i + 1})** [${song.title}](${song.url})
`
);
}

const pages: any = [];
for (let i = 0; i < pagesNum; i++) {
const str = tracks.slice(i * 5, i * 5 + 5).join('');
const embed = new EmbedBuilder()
.setAuthor({
name: `Queue for ${interaction.guild!.name}`,
iconURL: interaction.guild?.iconURL()?.toString()
})
.setColor('Red')
.setDescription(`**Now Playing:** [${title}](${url})\n\n**Queue:** ${str === '' ? '*No more queued songs*' : `\n${str}`}`)
.setFooter({
text: `${queue.tracks.length} song(s) in queue`
});

pages.push(embed);
}

const paginatedMessage = new PaginatedMessage().addPageEmbed(pages[0]);
if (pagesNum > 1) paginatedMessage.addPageBuilder((builder) => builder.setEmbeds(pages));

return paginatedMessage.run(interaction, interaction.user);
This code creates a paginated message, however when I add more embeds using builder.setEmbeds(pages), I want it to edit the current message to display the next pages, rather than send all embeds at once in the chat. Is there any way I can solve this?
30 replies