Obtaining Guild Name Doesn't Seem To Work v13.4.

Hi, I have returned to a year old bot and it seems that a function about getting and listing all guilds isn't detecting any guilds attached. When checked about length it is equal to 0. The function in question:
module.exports = async (message) => {

let guilds = await message.client.guilds.cache.values();
let guildNames = ''
for (let i = 0; i < guilds.length; i++) {
guildNames = guilds[i].name + "\n"
}
console.log(guildNames)
return
}
module.exports = async (message) => {

let guilds = await message.client.guilds.cache.values();
let guildNames = ''
for (let i = 0; i < guilds.length; i++) {
guildNames = guilds[i].name + "\n"
}
console.log(guildNames)
return
}
3 Replies
d.js toolkit
d.js toolkit3w 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!
Kinect3000
Kinect30003w ago
Pretty sure Map.values() returns an Iterator, not an Array You should just do for (const guild of client.guilds.cache.values()) {…} Better yet, just map and join the Collection Are you sure the bot is in a guild? The only other way it’s empty is if you have cache settings that prevents guilds from being cached or you clear the cache yourself
VoidKaz
VoidKazOP3w ago
The bot is in 3 guilds. After applying this, it works fine. Thank you. :pepoHeart:
Want results from more Discord servers?
Add your server