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

208
Views
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 answers
Answer question

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