2

I am trying to find the guild owner ID for all of my guilds to send them a direct message at a given time. My current implementation where I know all the guildIDs already and just iterate through them: message.client.guilds.cache.get(guildID).ownerID This currently works and is fine but I wonder about its robustness when I increase my guild count. I am currently testing on just 2 guilds but could reach upwards of 1000.

Lots of the older tutorials and questions on this site suggest not needing to use the .cache property of message.client.guilds and just getting your desired property like this message.client.guilds.get(desired_property) However when I try and go by their advice I get an error. This question had a similar problem to the one I was having but then fixed it when I used the .cache property of message.client which solved my problem previous problem. I then think I found why as this answer to a similar questions tells me that all user objects have been cached

What will this mean when I have upwards of 1000 guilds? Dont worry about sharding that is something I can think about later.

I have a loose understanding of how a cache works but will this therefore break down when I get into more guilds as not all of the guilds will be cached and therefore when I use message.client.guilds.cache.get(guildID).ownerID will I only get the ownerIDs of those guilds that have been cached or are all of the guilds the bot is in cached all the time? If this will not always return all the ownerIDs when the bot begins having thousands of guilds and therefore potentially not all of the guilds are cached is there a way in which I can fix it so it will always return them all?

Ortovox
  • 382
  • 10
  • 18

2 Answers2

2

You can also use .map:

let list = bot.guilds.cache.map(g => g.ownerID).join('\n');
message.channel.send(list)

Not sure about cache errors though, I've had some with users, but that was kind of expected. (used .users.fetch instead, that's a promise so make sure to use await if you're going to try that)

Crist
  • 358
  • 2
  • 12
  • Thanks, all sorted now though. Turns out you can set cache settings on your client class and to always fetch from the API you need to make sure you .fetch with a promise – Ortovox Nov 12 '20 at 10:56
0

([ ${client.guilds.cache.map(g => g.name).join(", \n ")} ]);

Toni_ALG
  • 13
  • 5
  • 1
    This answer was reviewed in the [Low Quality Queue](https://stackoverflow.com/help/review-low-quality). Here are some guidelines for [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). Code only answers are **not considered good answers**, and are likely to be downvoted and/or deleted because they are **less useful** to a community of learners. It's only obvious to you. Explain what it does, and how it's different / **better** than existing answers. [From Review](https://stackoverflow.com/review/low-quality-posts/32408819) – Trenton McKinney Aug 05 '22 at 18:58