Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Direct message in discord.js

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}`)


    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Discord.js makes this pretty easy:

const member = guild.members.cache.get(targetUsers.id)
member.roles.add(role)
member.send("Message here")

Altough be warned some users may have disabled direct messages from non friends on discord!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!