Sharding retrieve guild data
- Discordjs 14.9.0
- Node 20.10.0
Can someone explain me why when I try to retrieve members data cache, the result is undefined ?
35 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- 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!
- ✅
Marked as resolved by staff:discord: Gateway - Sharding
As apps grow and are added to an increasing number of guilds, some developers may find it necessary to divide portions of their app's operations across multiple processes. As such, the Gateway implements a method of user-controlled guild sharding which allows apps to split events across a number of Gateway connections. Guild sharding is entirely controlled by an app, and requires no state-sharing between separate connections to operate. While all apps can enable sharding, it's not necessary for apps in a smaller number of guilds.
read more
since each shard is on its own process communicating over IPC,
broadcastEval
results need to be jsonified before they're returned to the original process (the same reason why you can't reference local variables declared outside the eval'd function)
therefore the guild returned won't actually be a Guild
instance, so as you can see, guild.members
is just an array of ids
you'll want to do whatever it is you need with that data in the broadcastEval
if you really need each GuildMember
instance
tbh I'm surprised you didn't already run into some Maximum call stack exceeded
error from attempting to return an object that has a reference to the Client
side note: you can pass the shard
option for broadcastEval
to just run on the shard with the given guild
(and you can use ShardClientUtil.shardIdForGuildId()
to determine which shard that is)@duck you mean to have access to the references of members, channels, roles etc., I have to stay inside the broadcastEval callback ?
yes
Understood, but what is the solution so that I can pass a callback function inside the broadcasteval ?
It is possible to do something similar ?
no
since each shard is on its own process communicating over IPC,broadcastEval
results need to be jsonified before they're returned to the original process (the same reason why you can't reference local variables declared outside the eval'd function) you'll want to do whatever it is you need with that data in thebroadcastEval
if you really need eachGuildMember
instance
What that mean exactly ? I need to prepare the data in broadcasteval before sending it back?
yes
AH
Ok thanks for your help, can you leave the ticket open for a few days thanks !
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
ok
This kind of action like guildMember.send must be done in the broadcasteval too ? @duck
it's more that you can't return the
GuildMember
as a GuildMember
from the broadcastEval
you can dm users from anywhere, including with <Client>.users.send()
Yes for dm users, i can use that way but for other cases like "guildMember.roles.add" I will be forced to send information to the broadcasteval?
since each shard is on its own process communicating over IPC, broadcastEval
results need to be jsonified before they're returned to the original process
none of the objects you return from a broadcastEval
will retain their classesok thanks
Does the information sent in client listener parameters need to go through the shard system with broadcasteval ?
I'm not fully sure what you're even asking here or what you're trying to do
if you're just adding logs for the
guildDelete
event, is there a reason you need to do it in a broadcastEval
?That <Client>.users.send() recovers all members across shards ?
No it's okay, I was wrong
I'm still not fully sure what you're asking here
<Client>.users.send()
sends a dm to the given user
I imagine discord does send the User
back as part of one of the requests associated, but it won't suddenly send it to all shards, especially when this method is entirely unrelated to sharding or the gateway at all
discord.js also does not send all data from every shard to every other shard
not sure what this has to do with "recovers all members"I am confused about the concept of sharding
If I understand sharding correctly, the goal is to split the bot into several bots separated by shards.
Knowing that client.users is not in the client.shard, do we have the list of members of all the shards gathered inside the client.users or not?
Knowing that client.users is not in the client.shardwell it's true that
client.users
is not in client.shard
since it's already on the client, but it is available from every shard's Client
(though actually I suppose the slightly redundant client.shard.client.users
could be considered 'in client.shard
')
do we have the list of members of all the shards gathered inside the client.users or not?first before answering this, what exactly do you need all members of every guild across every shard for?
you intend to send a dm to every member in every guild?
Mass DMing users is not allowed as per developer ToS, considered spam and can get you and your bot banned.
- Mention
@everyone
to inform all your users at once instead
- Discord Developer Terms of Service: learn more | FAQ summaryNot massive dm
I mean send a dm to specific guild member
so then you don't need access to every member object from every guild
just use
<Client>.users.send()
kk thanks
is this right way to get user id ?
I want to notify user via dm message but is don't work
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
Am sry HAHAHA wrong thread
Check for error
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View