Role cache get undefined

const guild = client.guilds.cache.get('929288640142663720');
let roles = [];
if (config.admin_role) {
config.admin_role.forEach(async (role) => {
console.log(role);
const roleFetched = guild.roles.cache.get(role);
console.log(roleFetched);
if (!roleFetched) return roles.push('[INVALID ROLE]');

roles.push(roleFetched);
await channel.permissionOverwrites.create(roleFetched.id, {
SendMessages: true,
ViewChannel: true,
AttachFiles: true,
AddReactions: true,
EmbedLinks: true,
ReadMessageHistory: true
})
});
} else {
roles.push("No roles were added to config.js file.");
}
const guild = client.guilds.cache.get('929288640142663720');
let roles = [];
if (config.admin_role) {
config.admin_role.forEach(async (role) => {
console.log(role);
const roleFetched = guild.roles.cache.get(role);
console.log(roleFetched);
if (!roleFetched) return roles.push('[INVALID ROLE]');

roles.push(roleFetched);
await channel.permissionOverwrites.create(roleFetched.id, {
SendMessages: true,
ViewChannel: true,
AttachFiles: true,
AddReactions: true,
EmbedLinks: true,
ReadMessageHistory: true
})
});
} else {
roles.push("No roles were added to config.js file.");
}
When i using this it backs undefined how could i get the role
2 Replies
d.js toolkit
d.js toolkit12h 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/luna12h ago
log the id or show your logs and show the full error

Did you find this page helpful?