Issues with caching discord.js

Got some caching issues with discord.js v12 and im trying to figure out how to get around this issue to be honest because it's limiting the functionality i wanna do.

So i did this mute function and i wanna check if they got the muted role, the issue here is it caches, and keeps giving the same result until i restart the bot.

The code looks like this

var discordMember = await message.mentions.members.first() || await message.guild.members.fetch(args[0]);
var role = await message.guild.roles.cache.find(role => == + "-mute");
var hasRole = await discordMember.roles.cache.has(;

The main issue here is:

var hasRole = await discordMember.roles.cache.has(;

it keeps returning either true or false, depending on when i restart the bot, how do i get around the caching issue??

1 answer

  • answered 2021-04-08 06:06 Benzon

    They way to handle the cache issue was to actually just use

    await message.guild.members.fetch({user: args[0], force: true})