[英]Discord.js V13 404 not found
Trying to get a user id with regex, and then sending them a dm.尝试使用正则表达式获取用户 ID,然后向他们发送 dm。 Not working at all.
根本不工作。 The args will be like.DM @usermention.
参数将类似于.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.然后,您将获得第二个 match
matches[1]
而不是第一个。
And then you are using the match, formatted as <@XXXXXXXX>
as an id, which is supposed to be numerical.然后你使用匹配,格式为
<@XXXXXXXX>
作为 id,它应该是数字。
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'这会在消息中获得第一个用户提及,并向用户发送消息“你好”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.