I want to create a reaction role bot but this line
const maths = message.guild.roles.cache.find(role => role.name === "Maths");
puts me this error : TypeError: Cannot read properties of undefined (reading 'guild')
how i can fix this ? Thanks !
index.js :
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"]}, {partials: ["MESSAGE", "CHANNEL", "REACTION"] })
require("dotenv").config();
const prefix = "!";
const fs = require("fs");
clientmands = new Discord.Collection();
const commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
clientmands.set(command.name, command);
}
client.on("ready", () => {
console.log("bot online");
});
client.on("message", message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === "reactionrole") {
clientmands.get("reactionrole").execute(message. args, Discord, client);
}
});
client.login(process.env.BOT_TOKEN);
reactionrole.js :
name: 'reactionrole',
description: "Sets up a reaction role message",
async execute(message, args, Discord, client) {
const channel = "889087325244629012";
const maths = message.guild.roles.cache.find(role => role.name === "Maths");
const mathsExpertes = message.guild.roles.cache.find(role => role.name === "Maths expertes");
const nsi = message.guild.roles.cache.find(role => role.name === "NSI");
const physique = message.guild.roles.cache.find(role => role.name === "Physique");
const svt = message.guild.roles.cache.find(role => role.name === "SVT");
const artsPlastique = message.guild.roles.cache.find(role => role.name === "Arts Plastiques");
const mathsEmoji = '