[Solved] How to add role to user after message is sent


To give a user a role, you need the MANAGE_ROLES permission and the bot also cannot give a role which has a higher position than its own. Other than that, the syntax for adding a role is pretty simple. First, you have to fetch the role, then you can add it to the user. To fetch the role, you can use .get() if you have the role id or .find() if you have the role name. Your code might look something like this:

const role = message.guild.roles.cache.get('roleid') // Or message.guild.roles.cache.find(r => r.name === 'rolename')
message.member.roles.add(role.id).then(m => {
    message.channel.send('Successfully added the role!')
}).catch(err => {
    message.channel.send('There was an error while adding the role!')
})

solved How to add role to user after message is sent