I want to make a whitlisted role to do a command and i puted this line
if (!message.guild.cache.roles.find(role => role.id === '873595824469344256')) return;
Error I get: Uncaught TypeError: Cannot read properties of undefined (reading 'roles')
const Discord = require("discord.js");
const { Client, Intents } = require('discord.js');
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGE_TYPING", "GUILD_MEMBERS", "GUILD_PRESENCES"] });
const config = require('./config.json');
const prefix = "g!"
bot.on("ready", () => {
console.log(`${bot.user.tag} bot is online`);
});
bot.on("messageCreate", message => {
if(message.content === prefix + "help") {
if (!message.guild.cache.roles.find(role => role.id === '873595824469344256')) return;
let helpembed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Help Guide')
.setAuthor('Request : ' + `${message.author.username}`)
.addFields(
{ name: 'Ban Usage', value: `${prefix}ban **id** | **reason** | **time** \n**__Exemple__** : ${prefix}ban id ALT-F4+Troll (without espace) 32H`},
{ name: 'Warn Usage', value: `${prefix}warn **id** | **reason** | **time** \n**__Exemple__** : ${prefix}warn id Bunny-Hope (without espace) warn-1/2/3`},
)
.setFooter('© ©');
message.reply({ embeds: [helpembed] });
};
});
Change your
if (!message.guild.cache.roles.find(role => role.id === '873595824469344256')) return;
to:
if (!message.member.roles.cache.has("873595824469344256")) return`