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

127
Views
Discord.js V13 404 not found

Trying to get a user id with regex, and then sending them a dm. Not working at all. The args will be like !DM @usermention.

const { MessageMentions: { USERS_PATTERN } } = require('discord.js');
const Discord = require("discord.js");
const Command = require("../Structures/Command.js");

module.exports = new Command({
    name: "DM",
    description: "Will DM given author",
    async run(message, args, client) {
        const matches = String(args).match(USERS_PATTERN);

        if (!matches) return;

        const id = matches[1];

        client.users.fetch(id).then(dm => {
            dm.send("Hello");
        })
    }
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are converting the array to a string before matching, which should work fine but I'm not sure it's what you want.

Then you are getting the second match with matches[1] instead of the first one.

And then you are using the match, formatted as <@XXXXXXXX> as an id, which is supposed to be numerical.

I would suggest replacing all that with simply:

async run(message, args, client) {
    message.mentions.users.first().send('Hello');
}

this gets the first user mention in the message and dms the user 'Hello'

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!