Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda