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

171
Views
How to have bot send specified user a DM?

I'm trying to create a warning command that DMs the specified user to notify them. Here is the specific code I'm trying to use:

    const user = await client.users
      .fetch(interaction.options.getString("user"), false)
      .catch(() => null);
    console.log(interaction.options.getString("user"));
    const embed = new MessageEmbed()
      .setColor("#FCE100")
      .setTitle(`⚠️ Warning!`)
      .setDescription(`${interaction.options.getString("warning")}`);
    await user.send({ embeds: embed }).catch(() => {
      interaction.channel.send(
        "Error: user not found"
      );
    });

The getString for user is correctly getting the user, as I've tested from console.log(). I can only assume the syntax is somehow wrong, although I can't seem to find the correct way to do this. The only error I'm getting is:

TypeError: Cannot read properties of null (reading 'send')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't need to use .getString().
CommandInteractionOptionResolver#getString() does it for you.
Make sure that you have the user option type set to "USER" before doing the code below.

const user = interaction.options.getUser("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!