Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda