Error fetching guild on client ready event
I have a function that will check for all guilds that have member count enabled
However this specific group of code seems to always fail to fetch the guild, even tho when evaluating the same code it succeeds.
This specific line
const guild = await client.guilds.fetch(g.guild).catch(() => {});
always returns void or undefined. Even tho the provided guild ID is valid.
This function is called from the ClientReady event.
12 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.Discord.js: v14.11.0
Node.js: v18.13.0
how many guilds do you have
because you might get ratelimited by doing that
My bot is in about 12 guilds right now, it is sharded if that causes an issue
why is is sharded for 12 guilds
Because im planning on advertising it
but it's not done
but seen the amount of fetch() calls you do, you're probably ratelimited
listen to the client.rest.on('ratelimit') event
Would it be better to pull from the cache?
Instead of fetching everything
if you have the guilds intent all guilds and channels should be cached
and guilds have a .memberCount property
I need to filter the members to remove bots
if you're gonna fetch the members for every guild, that is gonna cause a ratelimit
I just rewrote that function to be cache based
nevermind already found an error in that
Whenever this function executes getting the guild from the cache is still returning undefined