Certain amount of infractions per page

let warnings = await db.find({
user: user.id,
guild: message.guild.id,
automod: flagCheck ? true : false
});
let warnings = await db.find({
user: user.id,
guild: message.guild.id,
automod: flagCheck ? true : false
});
for (const warn of warnings) {
fields.push({
name: `${warn.type} | ID: ${warn.id}`,
value: `> **Reason:** ${warn.reason}\n> **Date:** <t:${warn.date}:f>\n${
warn.expires === 'Never' ? '' : `> **Expires:** <t:${warn.expires}:f>`
}`,
inline: false
});
}
for (const warn of warnings) {
fields.push({
name: `${warn.type} | ID: ${warn.id}`,
value: `> **Reason:** ${warn.reason}\n> **Date:** <t:${warn.date}:f>\n${
warn.expires === 'Never' ? '' : `> **Expires:** <t:${warn.expires}:f>`
}`,
inline: false
});
}
This is how I get a list of warnings of the provided user, my question is, how can I make it so there's pages with certain amount of infractions shown in each page? I'm using PaginatedMessages from @sapphire/discord.js-utilities
21 Replies
ararou!
ararou!•11mo ago
wdym? like limit the amount of fields in a page? if so, there should be a setItemsPerPage function like <new PaginatedMessageEmbedFields>.setItemsPerPage(10)
-Carlos👑
-Carlos👑OP•11mo ago
[ERROR] Encountered error on message command "warnings" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\commands\Moderation\warnings.js" TypeError: Cannot read properties of undefined (reading 'title') Code: https://pastebin.com/mr57SHTd
Pastebin
Paginated Messages - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
-Carlos👑
-Carlos👑OP•11mo ago
oh and it says .setItemsPerPage is not a function
Favna
Favna•11mo ago
PaginatedMessage and PaginatedMessageEmbedFields are different classes Rather the second extends the first
-Carlos👑
-Carlos👑OP•11mo ago
ah alright what about this error [ERROR] Encountered error on message command "warnings" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\commands\Moderation\warnings.js" TypeError: Cannot read properties of undefined (reading 'title') wait hold up I think I got it how do I set an author icon [ERROR] Encountered error on message command "warnings" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\commands\Moderation\warnings.js" DiscordAPIError[50035]: Invalid Form Body embeds[0].author[MODEL_TYPE_CONVERT]: Expected an object/dictionary. embeds[0].color[NUMBER_TYPE_COERCE]: Value "#2f3136" is not int. .
Favna
Favna•11mo ago
author needs to be an object matching APIEmbedAuthor: https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedAuthor Or do the sensible thing and use EmbedBuilder:
new PaginatedMessageEmbedFields()
.setTemplate(new EmbedBuilder().setAuthor({ name: author, iconURL: user.displayAvatarURL() }))
.setItems(fields)
.setItemsPerPage(infractionsPerPage)
.make()
.run(message);
new PaginatedMessageEmbedFields()
.setTemplate(new EmbedBuilder().setAuthor({ name: author, iconURL: user.displayAvatarURL() }))
.setItems(fields)
.setItemsPerPage(infractionsPerPage)
.make()
.run(message);
(also I know you write JS but I implore you to consider switching to TS because it would've warned you that that is invalid code before you ran it)
discord-api-types documentation
discord-api-types - Imagine typings
discord-api-types is a simple Node/Deno module that brings up to date typings for Discord's API
-Carlos👑
-Carlos👑OP•11mo ago
i was going to switch to ts like a week ago but got too lazy anyways ty I have a few questions: Why color doesn't accept hex codes? How to edit the footer How to remove the select menus oh and is there a way to change from which page the list starts? I want users to be able to do >warnings [page]
Favna
Favna•11mo ago
Why color doesn't accept hex codes?
https://discord.js.org/docs/packages/builders/1.7.0/EmbedBuilder:Class#setColor. Strings were removed in either DJS v13 or v14, I forgot which. Change it to
const colors = {
black: 0x2f3136
}
const colors = {
black: 0x2f3136
}
FYI this counts for ALL embeds with DiscordJS, NOT just PaginatedMessage
How to edit the footer
Set the footer in the template. You can remove the page index bit with https://www.sapphirejs.dev/docs/Documentation/api-utilities/classes/sapphire_discord_js_utilities.PaginatedMessage#setshouldaddfootertoembeds
How to remove the select menus
Override the actions, search this forum/server for examples. There are many. Just search for "actions". The short version is filtering it out of PaginatedMessage.defaultActions
oh and is there a way to change from which page the list starts?
No, but you can remark it in #paginated-messages-v2 for the future as a request.
-Carlos👑
-Carlos👑OP•11mo ago
I actually wanted to add text before the page index, not after
Favna
Favna•11mo ago
ah no that's not possible
-Carlos👑
-Carlos👑OP•11mo ago
oh alright
Favna
Favna•11mo ago
what text if I might ask? wondering why it cant be behind
-Carlos👑
-Carlos👑OP•11mo ago
just wanted to add Page so it looks like Page 1 / 1 but it doesn't matter that much
Favna
Favna•11mo ago
you can do that by setting the pageIndexPrefix in the constructor or set PaginatedMesasge.pageIndexPrefix in your entrypoint to apply it to all PaginatedMessage instances
-Carlos👑
-Carlos👑OP•11mo ago
alright thanks TypeError: (intermediate value).pageIndexPrefix is not a function
.pageIndexPrefix('Page')
.pageIndexPrefix('Page')
Favna
Favna•11mo ago
read carefully what I said
-Carlos👑
-Carlos👑OP•11mo ago
ah . am I using setWrongUserInteractionReply correctly? Looks like it's not working and is there a way to make the .run ephemeral? On the docs it says wrongUserInteractionReply but on my auto complete is says setWrongUserInteractionReply btw
Favna
Favna•11mo ago
the one is the property, the other the method and to make it ephemeral first defer the reply with ephemeral
-Carlos👑
-Carlos👑OP•11mo ago
alright ty sorry for re-opening an old post, but what's the name of that color format?
Favna
Favna•11mo ago
Hexadecimal
Want results from more Discord servers?
Add your server