My bot runs a reminder system. For the past 6-8 months, this system has been working without a single issue. Recently it started to not work for a particular user, and upon investigating, when I look at my cache for the Guild it’s running off, it only returns two members. It returns my user (I do not own the Discord), and itself. I’ve never had this issue before, so I’m not sure why it’s not working. Using the Fetch method does not work, as it won’t let me send a DM to a user it fetches.
And for reference, the Guild actually has 104 members. That’s why I’m confused why it’s returning just 2.
I’ve tried using cached members, fetching members, getting the guild from the cache, finding members based on channel members.
Here is the code that the reminder system is using.
if(settingsCheck('Reminders') === true){
let array = fs.readdirSync(`${__dirname}/reminders/`)
const currentDate = new Date();
const timestampInMs = currentDate.getTime();
const unixTimestamp = Math.floor(currentDate.getTime() / 1000);
array.forEach(async (element) => {
let rawData = fs.readFileSync(`${__dirname}/reminders/${element}`)
let jsonData = JSON.parse(rawData);
if(jsonData.time < unixTimestamp){
await client.guilds.cache.get(config.guildID).members.cache.get(jsonData.user_id).send({ content: `<@${jsonData.user_id}> **SCHEDULED REMINDER** n<t:${jsonData.time}>: ${jsonData.reminder}`})
fs.unlinkSync(`${__dirname}/reminders/${element}`)
console.log(client.guilds.cache)
}
})
}
}
2
Answers
I spoke with Discord.JS's staff team and they were able to help me out. If the cache isn't up to date, you can run client.guilds.cache.get(GuildID).members.fetch(), and this will update the cache. fetchAllMembers is not a function in Discord.JS.
This issue almost always leads to one reason and thats that you dont have intents enabled.
Go to Developer Portal
Then enable these intents on your bot
Also consider using CRON as it may simplify your reminder system