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;
}
}
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;
}
}
2 Replies
d.js toolkit
d.js toolkit7mo 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! - Marked as resolved by OP
Adam
AdamOP7mo ago
Just realized after some time, it just sends an error. I will be working working on fixing the issue. No need is needed now, sorry.
Want results from more Discord servers?
Add your server