Discord.js-如何将用户ID转换为会员

时间:2020-07-27 00:28:41

标签: javascript discord.js

我想知道如何将ID转换为会员。我要转换的ID在.JSON文件中。我有这个脚本:

if(message.content == "!fl leaderboard") {
        embed = new Discord.MessageEmbed()
        const c = Object.entries(db).sort((a, b)=> b[1].level - a[1].level)
        for(const [key, value] of c) {
            embed.addField(db[message.author.id].tag, `Level: ${value.level} | XP: ${value.xp}`)
        }
        message.channel.send(embed)
    }


这就是它发布的内容:enter image description here

关卡系统的脚本为:https://hastebin.com/epucihenin.js

2 个答案:

答案 0 :(得分:1)

const User = client.users.cache.get("userid");
if (!User) return console.error("Couldn't find the user"); // Note that the user must be in a Guild with your bot for this to work.

console.log(`I found the user ${User.username}.`);

答案 1 :(得分:0)

您可以使用guild.member()从用户对象中获取成员对象,也可以使用client.users.fetch()从ID中获取用户对象。

.member()

.fetch()