【问题标题】:discord.js how to get a Discord username from a user IDdiscord.js 如何从用户 ID 获取 Discord 用户名
【发布时间】:2023-04-11 09:43:01
【问题描述】:

我正在编写一个 Discord 机器人,我想从用户 ID 中获取 Discord 用户名,这样我就知道谁为我的机器人投票了 我已经尝试使用谷歌找到答案,但它并没有真正告诉我

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    您需要从您的客户那里收集用户。

    const Discord = require("discord.js");
    const client = new Discord.Client();
    
    //This return the username of the specified user ID.
    const user = client.users.cache.get("USERID");
    if (!user) return console.log("Couldn't find the user");
    console.log(user.username)
    

    【讨论】:

    • 好的,但是如果没有人在我的机器人所在的同一台服务器上,我该怎么做
    猜你喜欢
    • 2019-12-30
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 2021-02-06
    • 2020-07-05
    • 2021-08-11
    • 2022-06-12
    • 2021-06-03
    相关资源
    最近更新 更多