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

211
Vistas
Getting user and sending DM Discord.js

I need to send a DM to a user, and I have a variable that stores a user's ID. I am aware of sending the message to the user using client.users.cache.get, and I'm also aware of fetching the user using client.users.fetch, but these only work if I specifically define the user's ID within the parentheses as a STRING.

client.users.fetch('XXXXXXXXXXXX') would work, but client.users.fetch(userid) using the variable, would not work. Any help?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So it really all depends on your trigger. Here are a few examples, all of which assume you are using Discord v13. And these are just a few examples. If you provide some code that you are trying to use, I can update this answer to give a more specific example.

client.on('messageCreate', async message => {
    const member = message.member

    member.send({
        content: 'Hi there'
    })
}
client.on('guildMemberAdd', async member => {
    member.send({
        content: 'Hi there'
    })
}
client.on('messageDelete', async message => {
    const member = message.member

    member.send({
        content: 'Hi there'
    })
}
client.on('messageReactionAdd', async (messageReaction, user) => {
    const member = messageReaction.message.member

    member.send({
        content: 'Hi there'
    })
})

To send messages based on a variable

const guildID = '098765432109876543'
const memberID = '123456789012345678'
const guild = client.guilds.cache.get(guildID)

guild.members.cache.get(memberID).send({
    content: 'Hi there'
})
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