DJS fetch function never ending?

Hey!
I'm making a bot for my boss that checks every <interval> for staff activity and I came accross an issue:
During the check execution, suddenly, everything stopped working fine, let me explain.
I tested while I was making it, everything worked. Woke up today and worked on it and it stopped working correctly: it is stuck at a members.fetch() function, no code runs after it even though it worked fine before.
Here is the piece of code where the error is found:
export async function runCheck(data: IGuild, check: ICheck, client: Bot) {
    const nextCheck = data.nextActivityCheck;
    console.log("ran check 1")
    const now = Date.now();
    if (nextCheck < now || !nextCheck) {
        console.log("ran check 2") // this code runs
        data.nextActivityCheck = now + data.activityCheckInterval;
        const members = await client.guilds.cache.get(data._id)?.members.fetch().catch(() => null);
        console.log(members)
        console.log("uwu") // ! this code is not executed, with the previous line too 
        // I tried doing a little debugging and found out it blocks on .fetch
        if (!members) return;
        console.log("ran check 3")
        const staffList = members.filter((m) => m.roles.cache.has(data.staffRole));
        data.staffList = [
            ...data.staffList,
            ...staffList.filter(
                (staff) => !data.staffList.some((existingStaff) => existingStaff.id === staff.id)
            ).map((m) => ({
                id: m.id,
                lastActivity: data.staffList.find((s) => s.id === m.id)?.lastActivity || 0
            }))
        ];

        await data.save();
        console.log("ran check 4")

        check.interval = setTimeout(() => runCheck(data, check, client), data.activityCheckInterval);
        check.activityTimeout = setTimeout(() => activityTimeout(data, client), data.activityCheckTimeout);

        await executeAction(data, client);
        console.log("ran check 5")

        return;
    }
}
Was this page helpful?