#guild members null

1 messages · Page 1 of 1 (latest)

summer wraith
shrewd pilot
#

lool

summer wraith
#

k, that is.. weird

#

version of discord.js in use? npm list discord.js

shrewd pilot
#

13.6

#
let guilds = [];
    client.guilds.cache.forEach(async (g) => {
        
        g.channels = null;
        g.roles = null;
        g.emojis = null;
        g.members = null;
        g.bans = null;
        g.scheduledEvents = null;
        g.stageInstances = null;
        g.invites = null;
        g.stickers = null;
        g.commands = null;
        g.features = null;
        
        await guilds.push(g);
    });

    await axios({
        method: "post",
        url: "https://status-bot-api.herokuapp.com/api/servers",
        headers: {
            "Authorization": "StatusBotIsBest",
            "Content-Type": "application/json"
        },
        data: guilds
    }).then(() => log(`Api`, `Servers Posted!`, `cyan`)).catch(() => null);```
#

i use this for api, does it have impact in bot lol

summer wraith
#

dude

shrewd pilot
#

eh?

summer wraith
#

you're literally modifying the cached guilds and set all kinds of stuff null we need internally for djs to function

shrewd pilot
#

isnt this just posting to my api, how does it impact on d.js?

summer wraith
#

?

#

you iterate over client.guilds.cache

#

and SET properties

#

you overwrite cached data

#

you're not making copies, you overwrite what's there

shrewd pilot
#

how can i make copy from that

summer wraith
#

what do you need for your API? push that as an object and set it to the value those guilds have, instead of overwriting those you don't want

shrewd pilot
#

i need object of guilds in array

summer wraith
#

what part of guild data do you need?

shrewd pilot
#

all excpet those that i try set to null

summer wraith
#

unlikely, you're trying to push a class instance over a HTTP call...

#

push data you need, not classes

#

can probs .toJSON() it

shrewd pilot
#

but it will still have impact to djs?

summer wraith
#

toJSON is a method that returns an object, which you can do whatever with

#

no, does not affect the cached structure

#

-ev msg.guild.toJSON()

mint daggerBOT
shrewd pilot
#

why not

shrewd pilot
summer wraith
#

then do that

#

but keep your fingers away from cached structure properties

#

no.

#

dude

shrewd pilot
#

data: guilds.toJSON()

#

just to make sure?

summer wraith
#

nah

#

still need to call it on each

shrewd pilot
#

where then

urban stratus
#

push data on each guild?

shrewd pilot
#

fuck i broke cache everything is null

summer wraith
#

@neon quest yes, that does not create a deep copy.

#

still has the exact same issue, class instances are passed by reference

shrewd pilot
#

how can i reset cache lol

summer wraith
#

restart the bot

shrewd pilot
#

not working xd

summer wraith
#

bs, we initiate empty caches and fill them with data as it comes in
if you kill the process and let it fully restart your changes are gone
unless that code still executes, somewhere, ofc

shrewd pilot
#

and it dies

#

ids are valid

summer wraith
#

that's not djs tho?

shrewd pilot
#

its in djs package code

summer wraith
#

?

shrewd pilot
#

i mean my cache is broken

summer wraith
#

container/events/client/ready.js is package code?

shrewd pilot
#

now

#

well no but it shows that cache is dead

summer wraith
#

what's the code there?

shrewd pilot
summer wraith
#

so you get an unhandled rejection somewhere before ready

shrewd pilot
#

i mean it worked so far lol

#

prb

#

sec

summer wraith
#

log the error before trying to send it to a channel

shrewd pilot
#

yeah

#
TypeError: guilds.toJSON is not a function
at Timeout._onTimeout (/home/container/index.js:153:22)```
#

lol

summer wraith
#

as said, each guild, not the collection

#

you didn't try to set nulls on the entire collection before either

#

if you want json data for all guilds, map the guild cache or sth

native nicheBOT
shrewd pilot
summer wraith
#

what do you call each guild during iteration (going over all)?

shrewd pilot
#

wdym

summer wraith
#

you are iterating over your guilds cache here

#

and you have a variable that's assigned each individual guild

shrewd pilot
#

probably

summer wraith
#

what is that variable?

#

that is literally your code

shrewd pilot
#

yes

#

lmao

summer wraith
#

then you should know what "g" is.

shrewd pilot
#

object

#

prb

summer wraith
#

of class?

shrewd pilot
#

wth is class

#

hold up

summer wraith
#

dude, you need to learn some js, i'm done here

shrewd pilot
#

just tell me where do i put to json druh

summer wraith
#

you call toJSON on each guild

#

the method returns an object with guild data

#

push that to your array, i guess

shrewd pilot
#

now i again got this

summer wraith
#

show code

shrewd pilot
#

bruh i tried get toJSON i tried push toJSON i dont have where to put that shit

summer wraith
#

?

#

okay, so let's try this again

#

client.guilds is a guild manager
client.guilds.cache is the cache of that manager
a cache is a collection of values, that are mapped by a key
the key for guild cache is the guilds id
the value for a guild cache is a guild (= discord server)

#

.forEach(fn) the forEach method iterates (goes over) the cache and passes the values inside it to the function fn

#

(g) => {...} a function that takes a parameter g and executes the body ... with it

#

plugging the latter into the place of fn will thus iterate all guilds and assign each guild to the variable g from which you can reference it

#

Guild is the class the discord.js library uses to represent discord servers
the Guild class has a method .toJSON which returns JSON data for this guild

#

collections hold instances of classes, so in this case g will be a Guild instance, which has the .toJSON() method to return its data

#

so within the function body ... you get the data for each guild <theGuildInstanceWeTalkedAboutAllThisTime>.toJSON() into your array and push that to your API

shrewd pilot
#

hold up let me read that

#

await guilds.push(g.toJSON()); ?

summer wraith
#

not sure where that await is suddenly from

summer wraith
#

and why is it there?

#

what does it do?

shrewd pilot
#

waits lmao

summer wraith
#

okay, so in summary:
you have absolutely no idea about javascript and cobble this together as you go

#

there is
a) no need for this function to be async
b) no need to call await, because push does not return a promise

native nicheBOT
#

<:_:818272565419573308> Array.prototype.push()
The push() method adds one or more elements to the end of an array and returns the new length of the array.

shrewd pilot
#

it littearly has no impact so why not

summer wraith
#

you do you, fam, you do you

shrewd pilot
#

well i thougth it takes time to push so i added