Comments (22)
Are you observing this in a barebones setup? I just tested your exact client options with the following code and did not find any null username
for(let g of client.guilds.cache.values()) {
if(g.available) {
let members = await g.members.fetch({ withPresences: true });
console.log(members.map(x => x.displayName).filter(x => !x))
}
}
The only way this would happen is if somehow a partial version of members are being cached by accident, in which case you would need to fetch with the force
option.
btw, the partials
client option is not needed in djsl.
from discord.js-light.
That's strange... the error is still occurring for me. I tried using the code below and got nonzero values for a large portion of my bot's servers.
for(let g of client.guilds.cache.values()) {
if(g.available) {
let members = await g.members.fetch({ withPresences: true });
console.log(members.filter(x => x.displayName == null).size);
}
}
In addition, I tried using the force
option when fetching as well and that did not resolve the issue.
I've never run into this issue when using the main discord.js library either 🤔.
from discord.js-light.
Are you using the latest npm version (3.5.3)? or the master version?
from discord.js-light.
I tried using both the latest npm version and the master version and encountered this issue on both.
from discord.js-light.
what does console.log(guild.members.cache.size, client.users.cache.size)
show before and after fetching members?
from discord.js-light.
Using the latest npm version:
Before fetching: 1, 1
After fetching: >1, 1
However, logging guild.members.cache.filter(x => x.displayName != null).size
returns 1, 1
after fetching.
from discord.js-light.
can you test this?
client.on("guildMembersChunk", (_, data) => console.log(data))
client.on("message", async m => {
if(m.content === "!!!test") {
const guild = m.guild;
console.log(guild.members.cache.size, client.users.cache.size, guild.memberCount);
const promise = guild.members.fetch({ withPresences:true });
console.log(client._events.guildMembersChunk.toString());
console.log((await promise).map(x => [x.user.username,x.presence.status]))
console.log(guild.members.cache.size, client.users.cache.size, guild.memberCount);
}
})
from discord.js-light.
Just ran the test a few times in a server with 18 members. The bot was unable to fetch any users except for itself, and the displayName
property was null
even though the members cache size was 18
. The statuses were always fetched without problem, but the members partial and the users were unable to be fetched at all.
from discord.js-light.
could you provide all the logging from the above code? can be in a pastebin or similar. Or if you prefer DM me on discord and we could continue over there
from discord.js-light.
Here's the link to the paste: https://pastebin.com/rkfVJLE4
from discord.js-light.
I still haven't been able to reproduce this behavior under normal conditions...
can you show this part console.log(client._events.guildMembersChunk.toString());
from the code above? I want to confirm if the function's code is correct.
The only way i could reproduce this behavior was by manually uncaching users in between fetching and mapping, are you perhaps attempting anything of the sort?
from discord.js-light.
Here is the code from console.log(client._events.guildMembersChunk.toString())
:
(c, d) => {
console.log(d);
}, (_, data) => {
if (data.nonce !== nonce) { return; }
timeout.refresh();
i++;
if (data.not_found) { failed += data.not_found.length; }
for (const member of data.members) {
fetched.set(member.user.id, this.add(member, options.cache || this.client.users.cache.has(member.user.id)));
}
if (presences && data.presences) {
for (const presence of data.presences) {
if (this.client.options.cachePresences || this.client.users.cache.has(presence.user.id)) {
this.guild.presences.add(Object.assign(presence, { guild: this.guild }));
}
}
}
if (
fetched.size >= this.guild.memberCount ||
(limit && fetched.size >= limit) ||
(typeof user_ids === "string" && fetched.size + failed === 1) ||
(Array.isArray(user_ids) && user_ids.length === fetched.size + failed) ||
i === data.chunk_count
) {
this.client.clearTimeout(timeout);
this.client.removeListener(Discord.Constants.Events.GUILD_MEMBERS_CHUNK, handler);
this.client.decrementMaxListeners();
if (typeof user_ids === "string") {
const result = fetched.first();
if (result) {
r(result);
} else {
j(new Discord.DiscordAPIError("GUILD_MEMBERS_CHUNK", { message: "Unknown User" }, "Gateway"));
}
} else {
if (!options.limit && !this.guild.memberCount) { this.guild.memberCount = fetched.size; }
r(fetched);
}
}
}
I encountered this behavior by manually uncaching all users (except for the bot itself) before fetching members. In addition, I encountered this behavior regardless of whether I manually cleared user caches between fetching and mapping (I tested both scenarios and got the same results).
from discord.js-light.
did you use client.sweepUsers()
or your own functions to clear users?
from discord.js-light.
I use client.users.cache.sweep(x => x.id != "bot ID")
from discord.js-light.
I am still not able to reproduce.
The following code returns 0 for all guilds in both "fetch" and "refetch" logs, with "after sweep" being the only one showing non-zero numbers, which is expected.
Discord = require("discord.js-light");
client = new Discord.Client({
partials: ["MESSAGE", "CHANNEL", "REACTION", "USER", "GUILD_MEMBER"],
ws: { intents: ["DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS", "GUILDS", "GUILD_BANS", "GUILD_EMOJIS", "GUILD_INVITES", "GUILD_MEMBERS", "GUILD_PRESENCES", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "GUILD_VOICE_STATES"] },
cacheChannels: true,
cacheEmojis: true,
cacheOverwrites: true,
cacheGuilds: true,
cacheRoles: true,
cachePresences: true,
});
client.login(token).catch(console.log);
client.on("ready", async () => {
for(let g of client.guilds.cache.values()) {
if(g.available) {
let members = await g.members.fetch({ withPresences: true });
console.log("after fetch", members.filter(x => x.displayName == null).size);
client.users.cache.sweep(x => x.id !== client.user.id);
console.log("after sweep", members.filter(x => x.displayName == null).size);
members = await g.members.fetch({ withPresences: true });
console.log("after refetch", members.filter(x => x.displayName == null).size);
}
}
})
If you're still getting different results with this exact code, try uninstalling both discord.js and discord.js-light, and reinstalling only discord.js-light, without discord.js
from discord.js-light.
On a test bot (in 2 servers) I was unable to reproduce this issue. Unfortunately, I got nonzero values for some fetch/refetch values on the main bot (in 150+ servers) using the exact code you provided, as shown in the logs here: https://pastebin.com/6qE4vnPC
try uninstalling both discord.js and discord.js-light, and reinstalling only discord.js-light, without discord.js
I used npm uninstall discord.js
then npm install discord.js-light
and still received nonzero values for some fetch/refetch values.
from discord.js-light.
well, im still not able to reproduce unfortunately, so i have no idea whats going on on your side...
try editing node_modules/discord.js-light/classes.js
and add these console.logs around lines 721-731, then repeat the above test and send the logs.
if(data.not_found) { failed += data.not_found.length; }
console.log("before members", this.client.users.cache.size, this.cache.size);
for(const member of data.members) {
fetched.set(member.user.id, this.add(member, options.cache || this.client.users.cache.has(member.user.id)));
}
console.log("after members", this.client.users.cache.size, this.cache.size);
if(presences && data.presences) {
for(const presence of data.presences) {
if(this.client.options.cachePresences || this.client.users.cache.has(presence.user.id)) {
this.guild.presences.add(Object.assign(presence, { guild: this.guild }));
}
}
}
console.log("after presences", this.client.users.cache.size, this.cache.size);
console.log(options, fetched.size, failed);
from discord.js-light.
Here are the logs: https://pastebin.com/8ARbpNpj
from discord.js-light.
The logs look fine, the function is caching as expected. Your users are somehow disappearing afterwards. Try logging caches again before and after r(fetched);
on line 755
from discord.js-light.
Are any guilds unavailable? This may be related to a known discord bug
from discord.js-light.
You need the Server Members Intent
to be enabled on your bot application in Discord in order to fetch large quantities of users
from discord.js-light.
i'll go ahead and close this since its very old and likely not relevant anymore
from discord.js-light.
Related Issues (20)
- Buttons Support HOT 10
- v13 HOT 3
- DMChannel does not have "recipient" in v3.5.11 HOT 3
- Privileged Intents Support HOT 2
- Threads Support HOT 1
- v13 is now the stable branch for discord.js HOT 2
- TypeError: Cannot read property 'slice' of null HOT 1
- LimitedCollection Typescript Error HOT 3
- Property 'forceSet' does not exist on type 'Collection<string, Channel>' HOT 18
- `guildCreate` doesn't get triggered on init HOT 4
- Can't set maxSize on cache. HOT 9
- Getting an error HOT 3
- Shards: "auto" not working HOT 4
- How to send webhook in the thread? HOT 2
- Error in makePartial and in actions HOT 17
- Cannot read properties of undefined (reading '_add') HOT 3
- MessageManager#forge doesn't set channel or guild data HOT 1
- discord-api-types conflicts HOT 2
- Discord.js V14 HOT 3
- How can I install discord.js-light master using npm? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discord.js-light.