#paginate function issue

1 messages · Page 1 of 1 (latest)

sturdy path
vast elm
#

alright

#

so

#

for reference

sturdy path
#

yessir

sturdy path
#

yep

vast elm
#

so

#

for clarification what are you trying to do with this

sturdy path
#

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.

vast elm
#

the paginate function sends the attachment and then reacts to it?

#

found the issue

sturdy path
#

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

vast elm
#

i think

sturdy path
vast elm
#

is embedArray an array of embeds?

#

or an array of embed arrays

sturdy path
#

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

vast elm
#

embedArray.push({embeds: [leaderboard]})
embed objects

sturdy path
#

yes

vast elm
#

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]})

sturdy path
#

oh

#

I see

vast elm
#

as you can see, it expects embeds: to be an array, not an object

sturdy path
#

hmm

vast elm
#

you are indexing the embedArray

#

but everything in the embedArray is an object

sturdy path
#

alright

vast elm
#

i think if you fix that

#

it should work

#

if it doesn't, lmk

sturdy path
#

alright

sturdy path
vast elm
#

if you just do embedArray.push([leaderboard]), it should(?) work

sturdy path
#

gotcha

#

I'm testing it rn

vast elm
vast elm
#

does it work?

sturdy path
#

nope unfortunately

vast elm
#

what's the error?

sturdy path
#
      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

vast elm
#

hold on

sturdy path
#

const pageMsg = await message.channel.send({ embeds: [embeds[0]] }) I think this is the affected line

vast elm
#

wait

#

why are you wrapping it in a

#

array

sturdy path
#

OH WAIT

#

I just noticed

vast elm
#

lmao

sturdy path
#

So basically instead of that, if I run const pageMsg = await message.channel.send({ embed: embeds[0] }) will it result in the intended outcome?

vast elm
#

should

#

assuming you did

#

embedArray.push([leaderboard])

sturdy path
#

mhm

#

did that

vast elm
#

yeah it should owrk

sturdy path
#

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

vast elm
#

can you update the pastebin?

#

that'd be nice

sturdy path
#

oh yeah sure

#

gonna do that rn

#

this is the updated pastebin

vast elm
#

ok

#

so

#

1 sec

sturdy path
#

take your time

vast elm
#

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

sturdy path
#

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

vast elm
#

yeah so

sturdy path
#

I don't think I know how to do that

#

how is it done?

vast elm
#

right below async function paginate(message, embeds, options) {

#

just do

#

console.log(embeds)

sturdy path
#

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

vast elm
#

ah

#

wait

#

is that all?

#

it's not in an array?

sturdy path
#

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

vast elm
#

no i mean like

sturdy path
#

oh wait

#

I know what you mean

vast elm
#

is the MessageEmbed

#

not in an array

sturdy path
#

It is in an array

#

hold on let me make another paste bin

vast elm
#

ok that's good

sturdy path
vast elm
#

so change

#

oh wow that's a large array

#

ok 1 sec

sturdy path
#

take your time

vast elm
#

description: '',

#

why is the description empty

#

there's no field either

sturdy path
#

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

vast elm
#

ok

#

so the issue here is

#

you have no description, and no fields

#

i don't think that's valid

sturdy path
#

hm

#

so how do I change that?

vast elm
#
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

sturdy path
#

I forgot actually, it's been a very long time since I made this function

#

I apologize for the inconvenience

vast elm
#

wait

#

its just

#

const pageMsg = await message.channel.send({ embeds: embeds })

#

you didn't have an s

#

lmao

sturdy path
#

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

vast elm
#

you have

#

way too many embeds

sturdy path
#

I need to get rid of some of them

vast elm
#

Math.ceil( Users.length / 10 )

#

for example

sturdy path
#

alright

#

where does this go again?

#

in the code

vast elm
#

err wait i have a question

#

so arey ou trying to send the FULL leaderboard

#

like every single user

sturdy path
#

yeah

vast elm
#

thats uh

#

wait

#

are you trying to do it like a menu

#

where you can go back and forth

sturdy path
#

by that I mean every single user that has made a post in the points channel and has received points for the post

sturdy path
vast elm
#

well fuck

sturdy path
#

so is there not an available solution for this issue?

vast elm
#

there absolutely is

#

i jsut didn't realize you were planning to do that

#

in that case

sturdy path
#

Oh sorry about that, I should have made it clearer in the beginning

vast elm
#

its fine i should've realized, gimme a sec

sturdy path
#

take your time

vast elm
#

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

sturdy path
#

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```
#

new pastebin to help make life easier

vast elm
#

fuck

#

i made another mistake

#

const pageMsg = await message.channel.send({ embeds: [ embeds[0] ] })

sturdy path
#

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

vast elm
#

well

sturdy path
#
      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```
vast elm
#

change

#

every single

#

pageMsg.edit({ embeds: embeds[pageIndex] })

#

to pageMsg.edit({ embeds: [ embeds[pageIndex] ] })

sturdy path
#

oh yeah i forgot

vast elm
#

btw

#

change

sturdy path
sturdy path
vast elm
#

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

sturdy path
#

aite I'll do that

vast elm
#

i think that shouldn't break in the future but

#

the i < math.ceil part might

#

idk i'm too tired for this

sturdy path
#

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

vast elm
#

just ignore the fact that this could've been solved in like 5 minutes if i wasn't a moron shhh

sturdy path
#

lol

#

but still though