#Help with attaching json data to attachment

50 messages · Page 1 of 1 (latest)

ionic anchor

Hey,

So weird one, a popular bot called "AmariBot", their support server got nuked last night (for me) meaning the bot is also kinda dead currently. It does levelling and things.

The issue which I have is that I have some data which I utilise their api with, leaderboard and weekly leaderboard, looks like this (first ss), and I want to get that data and either write it to a file or send it as an attachment to a channel for safe keeping, but I'm not too sure how.

tender patrolBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
ionic anchor

I tried using

Buffer.from(JSON.stringify(client.Giveaway.leaderboard.data))

But I got a SyntaxError: Invalid or unexpected token error

short coral

That isn’t pure JSON though. Those are actual class instances

ionic anchor

How would I be able to get like

I don't know how to word it

short coral

Well, what is it? Is it data from a db like mongoose or sequelize?

ionic anchor

No, it's using the amari api

short coral

Is that a npm package?

ionic anchor

Yh

I have the class as it comes with the npm thing iirc

The support server got nuked and a lot of servers aren't using the bot anymore due to who knows what's happening with it. So I'm trying to see if I can preserve the levels and things

short coral

That package seems to return raw JSON though, so it‘s weird that your log would show it as class instances of class Leaderboard and User thereThonk

ionic anchor

Could I maybe map over the data and create my own

I use getRawGuildLeaderboard which iirc I've got a slightly older version, since I did myself ask for a full leaderboard

short coral
ionic anchor

I don’t See that in their docs or their repo anywhere, their API you linked to doesn’t have thosewaitWhat

ionic anchor

That's the npm package

Looks like it completely died lol

here we go

short coral

But not their recent version, which version is it you use there? The current npm package only returns raw json, no structures

ionic anchor

1.6.1 💀, there's been a few updates since then lol

lofty coral

Maybe map the data to make it a json or whatever, and put it in a file with fs, and send it

short coral

You‘d want the .rawData property, as that’s the json you’re after

ionic anchor
lofty coral

Also no offense but this package is useless

lofty coral
short coral

Huh? It’s wrapping accessing their API, how is that useless?

ionic anchor

I'm gonna try making my own but it'll likely be hard with my current knowledge

lofty coral
ionic anchor

since the bot is kinda kapoot rn

short coral
lofty coral
ionic anchor

Ok, doing that I got a buffer

Buffer.from(JSON.stringify(client.Giveaway.leaderboard.data.map((val) => { return { id: val.id, username: val.username, exp: val.exp, level: val.level }}))
short coral

Now pass that into AttachmentBuilder and set a name

ionic anchor

syntax is wrong but I blindly copied lol

ionic anchor

idrk how buffers work... sorry

lofty coral
ionic anchor

Ahhhhh

Yes

lofty coral
let buffer = Buffer.from(JSON.stringify(client.Giveaway.leaderboard.data.map((val) => ({ id: val.id, username: val.username, exp: val.exp, level: val.level }))))
let attachment = new AttachmentBuilder(buffer , { name: "file.json"})

something like this

ionic anchor

Yep

Got it

Thank you so much guys