从加标签的用户获取ID [英] Getting ID from tagged user

查看:58
本文介绍了从加标签的用户获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hey I was wondering if I can check if someone is being tagged and if they are get the user ID of the person tagged and use it as reporting

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.")


推荐答案

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

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

You could use my discord-mentions package to extract the desired mention out of the string. See the package page for more details and specific usage.

示例:

// 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.

这篇关于从加标签的用户获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆