#paginate function issue
1 messages · Page 1 of 1 (latest)
alright
so
for reference
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.
yessir
yep
This is basically like a reddit-like post upvote/downvote system. People can post attachments into a certain channel, their post gets points through upvotes/downvotes/awards, and then to see how many points they have and where they're on the leaderboard, they can use the leaderboard command in order to do just that.
the paginate function is there to react to the embed (which is sent through line 253 in the pastebin), and then it helps the users go through the embed arrays
i think
what line is it in?
an array of embed arrays
the bot basically takes the values from the database, splits them into sets of 10 and then forms embed arrays for each set
embedArray.push({embeds: [leaderboard]})
embed objects
yes
when you do paginate
and edit it
it expects an array of embeds, you are giving it an object of embeds
embedArray.push({embeds: [leaderboard]})
as you can see, it expects embeds: to be an array, not an object
hmm
alright
alright
What do I put in instead of leaderboard in this line?
if you just do embedArray.push([leaderboard]), it should(?) work
the error here as you can see is that objects don't have a map function, but arrays do
yeah
does it work?
nope unfortunately
what's the error?
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Form Body
embeds[0].description: This field is required
at RequestHandler.execute (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)```
this is coming from the paginate function I believe
hold on
const pageMsg = await message.channel.send({ embeds: [embeds[0]] }) I think this is the affected line
lmao
So basically instead of that, if I run const pageMsg = await message.channel.send({ embed: embeds[0] }) will it result in the intended outcome?
yeah it should owrk
however:
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)```
its the classic cannot send an empty message case this time around
oh yeah sure
gonna do that rn
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.
this is the updated pastebin
take your time
wait
just try changing
embedArray.push([leaderboard]) to embedArray.push( leaderboard )
const pageMsg = await message.channel.send({ embed: embeds })
if that doesn't work, would you mind logging the embedarray when paginate receives it
and tell me what it says
sure
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)
at async paginate (/home/runner/LBTV13/commands/leaderboardOne.js:261:21) {
method: 'post',
path: '/channels/764442812480618526/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
Node.js v17.0.1```
doesn't work, it's the same empty message error
yeah so
do this
right below async function paginate(message, embeds, options) {
just do
console.log(embeds)
oh ok
will do
it logged the embed
type: 'rich',
title: "Here is The Boomer Incorporated's points | awards leaderboard!",
description: '1. @rain vault: 4 | undefined\n' +
'2. @urban ruin: 3 | undefined\n' +
'3. @young bison: 1 | undefined\n' +
'4. @lost ore: 0 | undefined\n' +
'5. @sturdy path: -9 | undefined\n',
url: null,
color: 10515698,
timestamp: 1645387152882,
fields: [],
thumbnail: { url: 'https://pbs.twimg.com/media/D7ShRPYXoAA-XXB.jpg' },
image: null,
video: null,
author: null,
provider: null,
footer: {
text: "By EBMOfficial, for everyone with the magic of discord.js. TIP: Leaderboard details not appearing? Use the command '^setLeaderboardChannel' in the desired channel to start activity on your server's leaderboard!",
iconURL: undefined
}
},```
this is what the actual embed is supposed to say
but the bot is not able to send it
this particular database only has like 5 values in it since its attached to the beta build of my bot, but the main bot's database does have more than 10 values
no i mean like
ok that's good
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.
take your time
I think its empty because there aren't anymore values in the database
oh and .AddFields() was never meant to be in the embed
I think
ok
so the issue here is
you have no description, and no fields
i don't think that's valid
for (var i = 0; i < Users.length % 10 + 10; i++) {
const leaderboard = new Discord.MessageEmbed()
.setTitle(`Here is ${message.guild}'s points | awards leaderboard!`)
.setColor("RANDOM")
.setThumbnail("https://pbs.twimg.com/media/D7ShRPYXoAA-XXB.jpg")
let text = ""
for (var j = 0; j < 10; j++) {
if (!Users[ i * 10 + j ]) break;
text += `${i * 10 + j + 1}. <@${Users[ i * 10 + j ].userid}>: ${Users[ i * 10 + j ].points} | ${Users[ i * 10 + j ].awards}\n`
}```
in this piece of code
you're ALWAYS doing it 10 times
actually the full thing is ```js
for (var i = 0; i < Users.length % 10 + 10; i++) {
const leaderboard = new Discord.MessageEmbed()
.setTitle(Here is ${message.guild}'s points | awards leaderboard!)
.setColor("RANDOM")
.setThumbnail("https://pbs.twimg.com/media/D7ShRPYXoAA-XXB.jpg")
let text = ""
for (var j = 0; j < 10; j++) {
if (!Users[ i * 10 + j ]) break;
text += `${i * 10 + j + 1}. <@${Users[ i * 10 + j ].userid}>: ${Users[ i * 10 + j ].points} | ${Users[ i * 10 + j ].awards}\n`
}
leaderboard.setDescription(${text})
.setFooter("By EBMOfficial, for everyone with the magic of discord.js. TIP: Leaderboard details not appearing? Use the command '^setLeaderboardChannel' in the desired channel to start activity on your server's leaderboard!")
.setTimestamp()
embedArray.push([leaderboard])
}```
i believe whats happening is that
wait what are you doing why is the +10 there
I forgot actually, it's been a very long time since I made this function
I apologize for the inconvenience
wait
its just
const pageMsg = await message.channel.send({ embeds: embeds })
you didn't have an s
lmao
good god 💀
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Form Body
embeds: Must be 10 or fewer in length.
at RequestHandler.execute (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/LBTV13/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)```
man
I need to get rid of some of them
err wait i have a question
so arey ou trying to send the FULL leaderboard
like every single user
yeah
by that I mean every single user that has made a post in the points channel and has received points for the post
yeah
well fuck
so is there not an available solution for this issue?
Oh sorry about that, I should have made it clearer in the beginning
its fine i should've realized, gimme a sec
take your time
ok
ok
so i made a mistake, you should've done
const pageMsg = await message.channel.send({ embeds: embeds[0] })
that [0] should've been there
alright
now it returns this error:
embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()),
^
TypeError: this.options.embeds?.map is not a function
at MessagePayload.resolveData (/home/runner/LBTV13/node_modules/discord.js/src/structures/MessagePayload.js:195:36)
at TextChannel.send (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:171:61)
at paginate (/home/runner/LBTV13/commands/leaderboardOne.js:262:44)
at Client.<anonymous> (/home/runner/LBTV13/commands/leaderboardOne.js:255:7)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Node.js v17.0.1```
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.
new pastebin to help make life easier
fuck
i made another mistake
const pageMsg = await message.channel.send({ embeds: [ embeds[0] ] })
Ok so this time
IT MANAGED TO SEND THE EMBED!
but whenever I try to go back and forth between the embeds in the array it dies
well
embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()),
^
TypeError: this.options.embeds?.map is not a function
at MessagePayload.resolveData (/home/runner/LBTV13/node_modules/discord.js/src/structures/MessagePayload.js:195:36)
at MessageManager.edit (/home/runner/LBTV13/node_modules/discord.js/src/managers/MessageManager.js:130:8)
at Message.edit (/home/runner/LBTV13/node_modules/discord.js/src/structures/Message.js:702:34)
at ReactionCollector.<anonymous> (/home/runner/LBTV13/commands/leaderboardOne.js:281:25)
at ReactionCollector.emit (node:events:402:35)
at ReactionCollector.handleCollect (/home/runner/LBTV13/node_modules/discord.js/src/structures/interfaces/Collector.js:109:12)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Node.js v17.0.1
exit status 1```
change
every single
pageMsg.edit({ embeds: embeds[pageIndex] })
to pageMsg.edit({ embeds: [ embeds[pageIndex] ] })
oh yeah i forgot
Just made this change and everything works as intended now
any other changes to be made?
for (var i = 0; i < Users.length % 10 + 10; i++) { to for (var i = 0; i < Math.ceil(Users.length / 10); i++) { so you don't have an extra 10 groups
aite I'll do that
i think that shouldn't break in the future but
the i < math.ceil part might
idk i'm too tired for this
I think you should get some rest now. The issue has been fixed finally! I don't know what I could have done without your help
You're an absolute legend for this
just ignore the fact that this could've been solved in like 5 minutes if i wasn't a moron shhh