#guild members null
1 messages · Page 1 of 1 (latest)
lool
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
dude
eh?
you're literally modifying the cached guilds and set all kinds of stuff null we need internally for djs to function
isnt this just posting to my api, how does it impact on d.js?
?
you iterate over client.guilds.cache
and SET properties
you overwrite cached data
you're not making copies, you overwrite what's there
how can i make copy from that
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
i need object of guilds in array
what part of guild data do you need?
all excpet those that i try set to null
unlikely, you're trying to push a class instance over a HTTP call...
push data you need, not classes
can probs .toJSON() it
but it will still have impact to djs?
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()
why not
yes i need that for every guild in array
then do that
but keep your fingers away from cached structure properties
no.
dude
where then
push data on each guild?
fuck i broke cache everything is null
@neon quest yes, that does not create a deep copy.
still has the exact same issue, class instances are passed by reference
can recommend eloquent javascript in #resources
how can i reset cache lol
restart the bot
not working xd
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
that's not djs tho?
?
i mean my cache is broken
container/events/client/ready.js is package code?
what's the code there?
so you get an unhandled rejection somewhere before ready
log the error before trying to send it to a channel
yeah
TypeError: guilds.toJSON is not a function
at Timeout._onTimeout (/home/container/index.js:153:22)```
lol
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
<:_:874569335308431382> Collection#map()
Maps each item to another value into an array. Identical in behavior to Array.map().
where do i put that json 
what do you call each guild during iteration (going over all)?
wdym
you are iterating over your guilds cache here
and you have a variable that's assigned each individual guild
probably
then you should know what "g" is.
of class?
just tell me where do i put to json druh
you call toJSON on each guild
the method returns an object with guild data
push that to your array, i guess
show code
bruh i tried get toJSON i tried push toJSON i dont have where to put that shit
?
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
not sure where that await is suddenly from
waits lmao
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
<:_: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.
it littearly has no impact so why not
you do you, fam, you do you
well i thougth it takes time to push so i added