首页 > 解决方案 > DISCORD.JS 如何使用@user 进行验证

问题描述

client.on('message', msg => {
    if(msg.content.startsWith('^approvedpr'))
    (What do I put here)? 
});

我尝试了其他人的所有代码,但没有成功。

标签: discord.js

解决方案


msg.author.send您可以通过查看消息类文档了解您可以执行的所有操作,向其他用户发送 DM 。

client.on('message', msg => {
    if (msg.content.startsWith('^approvedpr') {
        msg.author.send("Whatever");
    };
};

编辑:如果您尝试 DM 提及的用户,您可以使用msg.mentions.users文档链接

client.on('message', msg => {
    if (msg.content.startsWith('^approvedpr') {
        //Get the first user that was mentioned
        const mention = msg.mentions.users.first();

        //Send them a DM
        mention.send("Whatever");
    };
};

推荐阅读