Fetching users with ShardManager
hey, how would this example work for fetches? Like users.fetch() : https://discordjs.guide/sharding/#fetchclientvalues
5 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Users.fetch
can be used in any shard anytime
The link you presented is for if the data between shards change
Which is not the case for the user fetchthanks for the clarification! : )
so there's no need to use FetchClientValues and BroadcastEval for fetching users? How do I know if data is shared between shards?
and does that mean I can simply use
interaction.client.users.fetch
or do I need the shard obj?
hi! i have some sort of global blacklist command where i can blacklist / check status of a user. The user is most likely not in the server so I have to check if they exist.
same for guilds, but afaik they are cached by default?
blacklist would me a developer (me) command only, so that I can term users / guilds from using any commands of my bot.
and for that I need to fetch the users / guilds
because I want to display the name of the user (or guild) I just blocked to prevent mistakes
the moment I blacklisted
so for the user a simple interaction.client.users.fetch()
and for guild broadcast or fetchClient?
i see, thank you!
I'm still unsure about when to use broadcastEval / fetchClientValues, should I use it whenever I need cache.get()
?
on guilds and text channels for example
I see, thanks for the note :) Looks a little hard at first glance but I'll see
thanks for the explanation! I'm quite unsure about the example you provided: broadcastEval('this.users.cache.random().constructor.name')
what exactly is random()
and constructor.name
?
could random be 'get' or 'size'?oh, I thought you want to tell us what it can be anything
i see! yea i just wanted to confirm that i can use anything on that.
does that mean I can also use
cache.get('SOME ID HERE')
?
some more questions, let's say I want a specific guild id.
1. couldn't I use client.guilds.fetch()
2. would it be like broadcastEval('this.guilds.cache.get('ID').id')
?
oh yeah, that really makes no sense here. what I did previously is to get the guild by it's id and check if it exists. I think there is no point in doing this here, right?
This is what I previously had, and I want to make it shard-friendly
it's some sort of /blacklist check
command where I check whether the guild is blacklisted or not
the guild id
yes
yes but here comes the problem from before, I want to display the guilds name in the response haha :D
i could just check if the id is in the database but I also need some fanciness
oh okay
Is c
the context?
it's the client right?
from what it looks like is that context.guildId
< context cannot be found as it's not in the scope. Is that just my ts crying or will it still work?
great that works!
okay thanks it's more clear now for me. is there some sort of list of objects that are not shared through all shards?
as far as I understood users can be fetched, guilds, messages and channels should be checked with bEval, is this right?
for your use case here you technically don't even really need to bEval, cause you could just fetch the guild locally, but that comes with waaaay more data than just name, and you don't need anything.this here confuses me, what are you suggesting me? If I fetch I'd get unnecessary data, right? but at the same time you tell me that I don't need bEval I usually don't need the whole object, just one variable - like
name
. so bEval would be better for me afaiu
thanks a bunch! thats a really good explanation :D
i think i get it now
but just one more question to make sure; it wouldn't hurt to stick to bEval, would it?
great thank you! it can be pain to find people that explain good and stay kind and patient, i was lucky to get zero two :)
okay one more question, iirc you said that it does not return a string in the example before.
does it return the function? if so, how do I check if the guild is existing and the name is no null / undefined?
Yes, but what exactly does broadcastEval() return? Isn't it possible to get the datatype that I return? In this example string
as I get the .name
?
Afaik it returns the function
If you ask like this I probably don't know
Yes
Sorry, it takes some repetitions for me to understand certain things
But I guess I understand it now