'Discord js Cannot read properties of undefined (reading 'add')

Hey I have a little problem.

I wan't to assign a discord role when the bot starts up I wan't it to work with id's like user id and role id but it is saying Cannot read properties of undefined (reading 'add')

Thanks in advance Neo

My intents are enabled on discord developer portal

const client = new Client({

intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS], }); // intents stuff

enter image description here



Solution 1:[1]

You don't need to use async/await for getting user from guild. Use get() instead of fetch() that's probably gonna solve your problem.

Solution 2:[2]

Thanks Gh0st Fixed it by doing this.

  const guild = client.guilds.cache.get('976862525801000960')
  const role = guild.roles.cache.get('978375133649592361')
  const member =  await guild.members.fetch('404645579705024523')

  member.roles.add(role).then( 
      console.log(`TOKEN: `) 
  )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Neenhila
Solution 2 Péèlo