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

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

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 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