const model = mongoose.model('autoShard');
let description = ``;
try {
const data = await model.find();
if (data.length === 0) {
return msg.reply('No active live shards');
}
for (const g of data) {
const guild = msg.client.guilds.cache.get(g._id);
if (!guild || !guild.name) continue;
const owner = msg.client.users.cache.get(guild.ownerId);
const channel = msg.client.channels.cache.get(g.channelId);
console.log("Guilds:", guild.name);
description += `**Guild:** ${guild?.name || "Unknown"} (${guild?.id || "Unknown"})\n**Owner:** ${owner?.username || "Unknown"} (${owner?.id || "Unknown"})\n**Channel:** ${channel.name} (${channel.id})\n\n`;
}
So this code give the error somehow that name is undefined. I tried logging name for each docs, and mongo returns two documents and both two names are logged, then how is it giving an erro for undefined name? I can't wrap my heads around it... i placed additional checks to circumvent it like continue but still it gives that.
Also i should mention that on my test bot which i run locally, it works, but from my host, it gives this erro which i don't understand how the host would be a problem