简体   繁体   English

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

[英]Discord.js - How do I convert user ID to Member

I am wondering how to convert an ID to a Member.我想知道如何将 ID 转换为会员。 The ID I want to convert is in a.JSON file.我要转换的 ID 在 a.JSON 文件中。 I have this script:我有这个脚本:

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)
    }


And this is what it posts:这就是它发布的内容: 在此处输入图像描述

The script of the level system is: https://hastebin.com/epucihenin.js关卡系统脚本为: https://hastebin.com/epucihenin.js

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}.`);

You can use guild.member() to get a member object from a user object, and you can use client.users.fetch() to get a user object from an ID.您可以使用guild.member()从用户 object 获取成员 object,您可以使用client.users.fetch()从 ID 获取用户 object。

.member() 。成员()

.fetch() 。拿来()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM