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 ?
No description
No description
35 Replies
d.js toolkit
d.js toolkit3mo ago
- 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
d.js docs
d.js docs3mo ago
: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
duck
duck3mo ago
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)
Lumi
LumiOP3mo ago
@duck you mean to have access to the references of members, channels, roles etc., I have to stay inside the broadcastEval callback ?
duck
duck3mo ago
yes
Lumi
LumiOP3mo ago
Understood, but what is the solution so that I can pass a callback function inside the broadcasteval ?
No description
Lumi
LumiOP3mo ago
It is possible to do something similar ?
duck
duck3mo ago
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 the broadcastEval if you really need each GuildMember instance
Lumi
LumiOP3mo ago
What that mean exactly ? I need to prepare the data in broadcasteval before sending it back?
duck
duck3mo ago
yes
Lumi
LumiOP3mo ago
AH Ok thanks for your help, can you leave the ticket open for a few days thanks !
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Lumi
LumiOP3mo ago
ok
Lumi
LumiOP3mo ago
This kind of action like guildMember.send must be done in the broadcasteval too ? @duck
No description
duck
duck3mo ago
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()
Lumi
LumiOP3mo ago
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?
No description
duck
duck3mo ago
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 classes
Lumi
LumiOP3mo ago
ok thanks
Lumi
LumiOP3mo ago
Does the information sent in client listener parameters need to go through the shard system with broadcasteval ?
No description
duck
duck3mo ago
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?
Lumi
LumiOP3mo ago
That <Client>.users.send() recovers all members across shards ? No it's okay, I was wrong
duck
duck3mo ago
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"
Lumi
LumiOP3mo ago
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?
duck
duck3mo ago
Knowing that client.users is not in the client.shard
well 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?
duck
duck3mo ago
you intend to send a dm to every member in every guild?
d.js docs
d.js docs3mo ago
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 summary
Lumi
LumiOP3mo ago
Not massive dm I mean send a dm to specific guild member
duck
duck3mo ago
so then you don't need access to every member object from every guild just use <Client>.users.send()
Lumi
LumiOP3mo ago
kk thanks
Perodix__
Perodix__3mo ago
const { Events } = require('discord.js');


module.exports = {
name: Events.GuildUpdate,
async execute(Guild, client, member) {

let vanity = await Guild.fetchVanityData();

if (!Guild.features.includes('VANITY_URL'))
{
console.log('Ovaj server nema omogućenu opciju za vanity URL.');
return;
}
console.log(vanity.code)

if(vanity.code == 'rejva')
{
return;
}
else {

let simke = Guild.client.users.fetch('673220464042049562');

simke.send("PEDERU JEDAN")

// channel.send("ALO")
// member.ban("")
}

},
};
const { Events } = require('discord.js');


module.exports = {
name: Events.GuildUpdate,
async execute(Guild, client, member) {

let vanity = await Guild.fetchVanityData();

if (!Guild.features.includes('VANITY_URL'))
{
console.log('Ovaj server nema omogućenu opciju za vanity URL.');
return;
}
console.log(vanity.code)

if(vanity.code == 'rejva')
{
return;
}
else {

let simke = Guild.client.users.fetch('673220464042049562');

simke.send("PEDERU JEDAN")

// channel.send("ALO")
// member.ban("")
}

},
};
is this right way to get user id ? I want to notify user via dm message but is don't work
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Perodix__
Perodix__3mo ago
Am sry HAHAHA wrong thread
awp only body
awp only body3mo ago
Check for error
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server