I am trying to make my discord bot to print all the servers that it's connected to but when I try to run my code I get this type error:
TypeError: client.guilds.forEach is not a function
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log("Conectat ca si: " + client.user.tag)
client.user.setActivity("my brother kiko jr", {type: "WATCHING"})
client.guilds.forEach((guild) => {
console.log(guild.name)
})
})
client.login("xyz")
I am assuming you're getting the error because you're using discord.js v12
If that is the case, your solution would be:
client.guilds.cache.forEach((guild) => {
console.log(guild.name);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With