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");
})
}
})
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'