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

160
Views
How can I use the USER ID instead of using the mentions?

I recently made a discord command called -dm that basically DMs the user mentioned in the message. Something like: -dm @Omega Hello! and it would send "Hello!" to the user mentioned.

But some people find it annoying when they get pinged multiple times, so I want to know if there is a way I could use the USER ID instead of mentioning the user. That would make life a lot more easier. For whom it may concern, my code is given below.

const Discord = require('discord.js')
module.exports = {
  name: 'dm',
  description: 'DMs the person with the User ID mentioned',
  execute(client, msg, args) {
    if(!msg.member.permissions.has("ADMINISTRATOR")) return msg.channel.send("You cannot do that!")
    //if(msg.author.id !== 'CENSORED') return msg.channel.send("You cannot do that!")

    const user = msg.mentions.users.first()
    if(!user) return msg.channel.send("That user ID doesn't exist OR that person isn't in the same server as me!")

    const str = args.slice(1).join(" ")
    user.send(str)
    msg.channel.send("Message sent to the user!")

    var dmLogger = new Discord.MessageEmbed()
    .setTitle("DM Sent")
    .setColor("RANDOM")
    .addField("MESSAGE SENT BY", msg.author.tag)
    .addField("MESSAGE SENT TO", user)
    .addField("MESSAGE CONTENT", str)
    .setTimestamp()

    client.channels.cache.get('CENSORED_2.0').send(dmLogger)
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could add await message.guild.members.fetch(args[0]) but if you still want to keep the mentions thing you can just add that to your user variable.

const user = msg.mentions.users.first() || await msg.guild.members.fetch(args[0])

If you want only with user ID, remove the mentions part.

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!