Accessing Specific Guild from Bot's Cache is not working
I hope this message finds you well. I am currently facing an issue with my Discord bot, and I'm seeking some guidance from the community.
Here's the problem I'm encountering:
1. When my bot joins a new guild, I can successfully access that guild using the
Events.GuildCreate
event. I retrieve it from the cache using client.guilds.cache
.
2. However, when I attempt to access a specific guild from the cache using the same client instance, I am getting "undefined." Additionally, when I check the Collection map, it appears to be empty.
I'm puzzled by this behavior and unsure why it's happening. Is there something I might be missing or doing incorrectly?
Am sharing my bot scopes, codes and output that am getting14 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!Joining bot code and logs
Accessing the guild by id and loging the cache
do you have the Guilds intent
this?
then you dont need to manually cache the guild
yeah it wasn't working so i tried by adding manually
How did you define client
Sorry, didn't get you.
How and where did you define discordClient and how do you call the function
Because it might not be logged in
If you use the guildCreate event, use <Guild>.client
I defiend my client inside backend config and accessed the client from there in many services inside nx mono repo. am logging the client by this function
Am getting guilds from there, but not from another service inside my Monorepo
But the client is same
Use <Guild>.client, most djs structures have a client property present