从加标签的用户获取ID

时间:2019-06-25 18:42:24

标签: javascript discord.js

嘿,我想知道是否可以检查某人是否已被标记,并且是否获得了该人的用户ID并将其用作报告

let [cmd, user, proof, reason] = msg.content.split(' ');
        let reporting = user //user being reported (usually tagged)
        let reported = msg.author.tag
        let reportedID = msg.author.id

let embedReply = new Discord.RichEmbed()
        .setColor("PURPLE")
        .setTitle("Ready to send?")
        .setDescription("Please check if this is correct:")
        .addField("Your name:", `${reported} (${reportedID})`)
        .addField("You are reporting:", `${reporting} (${reporting.id})`)
        .addField("With the proof:", proof)
        .addField("With the reason:", reason)
        .setFooter("Please check this report so you know what you're sending.")

1 个答案:

答案 0 :(得分:0)

我是此答案中显示的npm软件包的作者。包含它的唯一原因是其易于使用和应用。

您可以使用我的discord-mentions包从字符串中提取所需的提及。有关更多详细信息和特定用法,请参见包装页面。

示例:

// Require the package.
const getMention = require('discord-mentions'); // Don't forget to install.

// Extract any mentions from 'reporting.'
let mention = getMention(reporting, message.guild);

// If there is a mention, assign the member to 'reporting.' Otherwise, search for them by tag.
if (mention) reporting = mention.member;
else reporting = message.guild.members.find(m => m.user.tag === reporting);

// If the mention was not of a (valid) member, or none could be found, return an error.
if (!reporting) {
  return message.channel.send(':x: Unknown user. Use a mention or their tag.')
    .catch(console.error);
}

// 'reporting' is now a GuildMember. Use 'reporting.user.id' for their ID.