【问题标题】:Getting ID from tagged user从标记的用户获取 ID
【发布时间】:2019-11-07 15:48:03
【问题描述】:

嘿,我想知道我是否可以检查某人是否被标记,以及他们是否获得了被标记人的用户 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.")

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    我是这个答案中显示的 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.
    

    【讨论】:

      猜你喜欢
      • 2021-09-25
      • 1970-01-01
      • 2017-01-21
      • 1970-01-01
      • 2021-04-09
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多