Blox
Blox

Reputation: 63

How to automatically add a role to a new guild member when they join a Discord guild

I have been trying for a quite a while to make a bot that should automatically give a certain role to any new user that joins my discord server and so far I haven't had any luck.

client.on('guildMemberAdd', member => {
  console.log('User ' + member.user.username + ' has joined the server!')
  var role = member.guild.roles.cache.find(role => role.name === 'Alive and Clean');
  member.addRole(role)
});

I have encounted an error that is TypeError: member.addRole is not a function.

Upvotes: 0

Views: 3887

Answers (1)

Syntle
Syntle

Reputation: 5174

Since discord.js v12 you now need to use roles.add() instead of addRole().

Upvotes: 2

Related Questions