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

345
Views
Discord bot - send DM to mentioned user

I want make bot that will send message to user that I mention for example I will type !hello @thomas#5555

And bot will send DM message "hello" to this user

if(message.content.startsWith(prefix + "sendHello")){
    const taggedUser = message.mentions.users.first();
    const user = client.users.cache.get(taggedUser.id);
    user.send('Hello');
    }

What's wrong? Keep getting this: "ReferenceError: client is not defined"

I defined client on the top of the code like this: "const Client = new Disocrd.Client();"

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since you defined your client as Client, you need to use that instead of client. You could also use message.client to access it from the message object.

about 4 years ago · Juan Pablo Isaza Report

0

First make sure you are initializing your Client correctly.

Try:

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

With discord.js v13 you need to add the intents you want your Client to receive. The Intents.FLAGS.GUILDS intents option is necessary for your client to work properly. You can see all Intents here.

Also for your command code, if someone tagged a User you don't need to fetch the User again. Just use the taggedUser variable.

const taggedUser = message.mentions.users.first(); // get User
if (!taggedUser) return message.channel.send('Please mention a user to fetch.'); // Check to see if a User was tagged.
taggedUser.send('Hi') // send to User
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!