I am learning to make a bot that of roles. Currently the bot works but I would like that when granting a role to the user it sends a welcome md but I am having problems with that. I tried to use
client.on("ready", () => {
client.users.fetch(targetUsers.id).then(user => {
user.send('hola mundo')}
)});
But it does not work
The idea would be that after executing member.roles.add(role) a message is sent to the same welcome user
module.exports = {
commands: 'giverole',
expectedArgs: "<Target user's @> <The role name>",
minArgs: 2,
permissions: 'ADMINISTRATOR',
callback: (message, arguments) => {
const targetUsers = message.mentions.users.first()
if (!targetUsers) {
message.reply('Please specify someone to give a role to.')
return
}
arguments.shift()
const roleName = arguments.join(' ')
const { guild } = message
const role = guild.roles.cache.find((role) => {
return role.name === roleName
})
if (!role) {
message.reply(`No existe un rol con el nombre"${roleName}"`)
return
}
const member = guild.members.cache.get(targetUsers.id)
member.roles.add(role)
message.reply(`Ese usuario ahora tiene el rol de ${roleName}`)
console.log(`${targetUsers.id}`)
}
}