I've seen many people get the Topology is closed error, but I've never seen a straight answer that doesn't only answer the question for the exact code snippet given, but generally gives an overview of what the topology is and how it works.
I'm following the WOK DiscordJSv12 tutorials on YT, and have the mute command cloned from the repo and added some tweaks to include embeds. But as soon as I ran the code i got the topology error.
Here is the file where I get the error:
const muteSchema = require('@schemas/mute-schema')
module.exports = (client) => {
const checkMutes = async () => {
console.log('CHECKING MUTE DATA')
const now = new Date()
const conditional = {
expires: {
$lt: now
},
current: true,
}
//The error is on this next line, it doesn't like that 'await'
const results = await muteSchema.find(conditional)
if (results && results.length) {
for (const result of results) {
const { guildId, userId } = result
const guild = client.guilds.cache.get(guildId)
const member = (await guild.members.fetch()).get(userId)
const mutedRole = guild.roles.cache.find((role) => {
return role.name === 'Muted'
})
member.roles.remove(mutedRole)
}
await muteSchema.updateMany(conditional, {
current: false,
})
}
setTimeout(checkMutes, 1000 * 60 * 10 )
}
checkMutes()
client.on('guildMemberAdd', async (member) => {
const { guild, id } = member
const currentMute = await muteSchema.findOne({
userId: id,
guildId: guild.id,
current: true,
})
if (currentMute) {
const role = guild.roles.cache.find((role) => {
return role.name === 'Muted'
})
if (role) {
member.roles.add(role)
}
}
})
}
Here's the other file that completes the logic of this file: link
Also here is the schema: link
And my mongo file that connects to mongo: link
So I'd like to know how to fix my issue, and also for future errors how I can solve it myself and what the error basically means, since there is no exact line of my own code specified in the error.