I have a problem with member.roles.cache.fetch()

import { Client, GatewayIntentBits } from 'discord.js';

const TEST_TOKEN = '';
const TEST_GUILD_ID = '';
const TEST_USER_ID = '';

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers
]
});

client.once('ready', async () => {
const guild = await client.guilds.fetch(TEST_GUILD_ID);
const member = await guild.members.fetch(TEST_USER_ID);
console.log(member.roles.cache);

const testFetchResult = await member.roles.cache.fetch();
console.log('Fetch result:', testFetchResult);

});

client.login(TEST_TOKEN);
import { Client, GatewayIntentBits } from 'discord.js';

const TEST_TOKEN = '';
const TEST_GUILD_ID = '';
const TEST_USER_ID = '';

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers
]
});

client.once('ready', async () => {
const guild = await client.guilds.fetch(TEST_GUILD_ID);
const member = await guild.members.fetch(TEST_USER_ID);
console.log(member.roles.cache);

const testFetchResult = await member.roles.cache.fetch();
console.log('Fetch result:', testFetchResult);

});

client.login(TEST_TOKEN);
why i can't use fetch method of RoleManager?
No description
6 Replies
d.js toolkit
d.js toolkit3w 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!
treble/luna
treble/luna3w ago
It indeed isnt you either use the cache, or fetch. Not both But you shouldn't have to fetch regardless if you have the Guilds intent Neither should you have to fetch the guild
Amgelo
Amgelo3w ago
and you aren't using the fetch method of RoleManager, you're using the fetch method of RoleManager#cache, which is a Collection (a Map)
elap1
elap1OP3w ago
Thanks for explanation I actually did have the intent enabled, and I was originally using the cache But then a bug occurred, and I suspected it was because the cached information wasn't the latest so, that's why I tried using fetch to get the updated data oh i see , however when i try
member.roles.fetch()
member.roles.fetch()
i got same error
treble/luna
treble/luna3w ago
Because it doesnt exist on a GuildMemberRoleManager
Amgelo
Amgelo3w ago
you need to fetch the member to get the roles, can't fetch only the roles

Did you find this page helpful?