title: TypeError: Cannot read properties of undefined (reading 'guild')
body: <p>I want to create a reaction role bot but this line</p>
  <p><code>const maths = message.guild.roles.cache.find(role =&gt; role.name === &quot;Maths&quot;);</code></p>
  <p>puts me this error : <strong>TypeError: Cannot read properties of undefined (reading 'guild')</strong></p>
  <p>how i can fix this ?
  Thanks !</p>
  <p>index.js :</p>
  <pre><code>const client = new Discord.Client({ intents: [&quot;GUILDS&quot;, &quot;GUILD_MESSAGES&quot;]}, {partials: [&quot;MESSAGE&quot;, &quot;CHANNEL&quot;, &quot;REACTION&quot;] })
  require(&quot;dotenv&quot;).config();
  
  const prefix = &quot;!&quot;;
  
  const fs = require(&quot;fs&quot;);
  
  client.commands = new Discord.Collection();
  
  const commandFiles = fs.readdirSync(&quot;./commands/&quot;).filter(file =&gt; file.endsWith('.js'));
  for (const file of commandFiles) {
      const command = require(`./commands/${file}`);
  
      client.commands.set(command.name, command);
  }
  
  client.on(&quot;ready&quot;, () =&gt; {
      console.log(&quot;bot online&quot;);
  });
  
  client.on(&quot;message&quot;, message =&gt; {
  
      if(!message.content.startsWith(prefix) || message.author.bot) return;
  
      const args = message.content.slice(prefix.length).split(/ +/);
      const command = args.shift().toLowerCase();
      if (command === &quot;reactionrole&quot;) {
          client.commands.get(&quot;reactionrole&quot;).execute(message. args, Discord, client);
      }
  
  
  
  });
  
  client.login(process.env.BOT_TOKEN);
  </code></pre>
  <p>reactionrole.js :</p>
  <pre><code>    name: 'reactionrole',
      description: &quot;Sets up a reaction role message&quot;,
      async execute(message, args, Discord, client) {
          const channel = &quot;889087325244629012&quot;;
          const maths = message.guild.roles.cache.find(role =&gt; role.name === &quot;Maths&quot;);
          const mathsExpertes = message.guild.roles.cache.find(role =&gt; role.name === &quot;Maths expertes&quot;);
          const nsi = message.guild.roles.cache.find(role =&gt; role.name === &quot;NSI&quot;);
          const physique = message.guild.roles.cache.find(role =&gt; role.name === &quot;Physique&quot;);
          const svt = message.guild.roles.cache.find(role =&gt; role.name === &quot;SVT&quot;);
          const artsPlastique = message.guild.roles.cache.find(role =&gt; role.name === &quot;Arts Plastiques&quot;);
  
          const mathsEmoji = '';
          const mathsExpertesEmoji = '';
          const nsiEmoji = '';
          const physiqueEmoji = '';
          const svtEmoji = '';
          const artsPlastiquesEmoji = '';
  
          let embed = new Discord.MessageEmbed()
          .setColor(&quot;#e42643&quot;)
          .setTitle(&quot;Selection des matière&quot;)
          setDescription(&quot;Choisis tes matières en cliquant sur la reaction qui correspond\n\n&quot;
              + `${mathsEmoji} : Maths\n`
              + `${mathsExpertesEmoji} : Maths Expertes\n`
              + `${nsiEmoji} : NSI\n`
              + `${physiqueEmoji} : Physique\n`
              + `${svtEmoji} : SVT\n`
              + `${artsPlastiquesEmoji} : Arts Plastiques\n`);
  
          let messageEmbed = await message.channel.send(embed);
          messageEmbed.react(mathsEmoji);
          messageEmbed.react(mathsExpertesEmoji);
          messageEmbed.react(nsiEmoji);
          messageEmbed.react(physiqueEmoji);
          messageEmbed.react(svtEmoji);
          messageEmbed.react(artsPlastiquesEmoji);
  
          client.on(&quot;messageReactionAdd&quot;, async(reaction, user) =&gt; {
              if (reaction.message.partial) await reaction.message.fetch();
              if (reaction.partial) await reaction.fetch();
              if (user.bot) return;
              if (!reaction.message.guild) return;
  
              if (reaction.message.channel.id == channel) {
                  if (reaction.emoji.name === mathsEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(maths);
                  }
                  if (reaction.emoji.name === mathsExpertesEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(mathsExpertes);
                  }
                  if (reaction.emoji.name === nsiEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(nsi);
                  }
                  if (reaction.emoji.name === physiqueEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(physique);
                  }
                  if (reaction.emoji.name === svtEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(svt);
                  }
                  if (reaction.emoji.name === artsPlastiquesEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.add(artsPlastique);
                  }
              } else {
                  return;
              }
          });
          client.on(&quot;messageReactionRemove&quot;, async(reaction, user) =&gt; {
              if (reaction.message.partial) await reaction.message.fetch();
              if (reaction.partial) await reaction.fetch();
              if (user.bot) return;
              if (!reaction.message.guild) return;
  
              if (reaction.message.channel.id == channel) {
                  if (reaction.emoji.name === mathsEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(maths);
                  }
                  if (reaction.emoji.name === mathsExpertesEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(mathsExpertes);
                  }
                  if (reaction.emoji.name === nsiEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(nsi);
                  }
                  if (reaction.emoji.name === physiqueEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(physique);
                  }
                  if (reaction.emoji.name === svtEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(svt);
                  }
                  if (reaction.emoji.name === artsPlastiquesEmoji){
                      await reaction.message.guild.members.cache.get(user.id).roles.remove(artsPlastique);
                  }
              } else {
                  return;
              }
          });
      }
  }
  </code></pre>