【问题标题】:Discord.js V13 404 not found未找到 Discord.js V13 404
【发布时间】:2022-01-05 19:09:53
【问题描述】:

尝试使用正则表达式获取用户 ID,然后向他们发送 dm。根本不工作。参数将类似于 !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");
        })
    }
})

【问题讨论】:

  • @skara9 非常感谢!这似乎成功了。没有错误出现。但它仍然没有发送dms。你能帮我解决这个问题吗?
  • 你有需要的意图吗?它们是什么?

标签: javascript node.js discord discord.js


【解决方案1】:

您在匹配之前将数组转换为字符串,这应该可以正常工作,但我不确定它是否是您想要的。

那么你将得到第二个匹配 matches[1] 而不是第一个。

然后你使用匹配,格式为<@XXXXXXXX> 作为id,应该是数字。

我建议用简单的替换所有这些:

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

这会在消息中获得第一个用户提及并发送用户“你好”

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 2021-12-03
    • 2021-11-09
    • 1970-01-01
    • 2021-10-12
    • 2021-10-16
    • 2022-01-02
    • 1970-01-01
    • 2021-11-26
    相关资源
    最近更新 更多