【问题标题】:discord.js user does not contain all propertiesdiscord.js 用户不包含所有属性
【发布时间】:2021-01-06 04:09:10
【问题描述】:

我正在尝试将我的 discord 机器人更新到 discord.js v12。 dc 是一个登录的不和谐机器人客户端

dc.users.fetch(id, false).then(user => {
    console.log(user);
}

我得到以下输出:

User {
  id: 'myId',
  username: 'myUsername',
  bot: false,
  discriminator: 'someNumber',
  avatar: 'stuff',
  flags: UserFlags { bitfield: 0 },
  lastMessageID: null,
  lastMessageChannelID: null
}

用户对象通常应该包含的所有属性在哪里? 以user.dmChannel 为例

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    这些属性(user.taguser.guild 等)是getter。这意味着它们是使用对象中的其他变量计算的。例如,tag 不是user 类的属性,它只是一个返回字符串的函数:

    get tag () {
        return `${this.username}#${this.discriminator}`;
    }
    

    这样更好,因为如果用户名发生变化,标签会自动更新。使用console.log(user); 看不到用户的所有getter,应该改用the documentation

    【讨论】:

    • 谢谢,我也在客户端准备好之前运行了这个。难怪没有任何效果
    猜你喜欢
    • 2013-08-10
    • 2021-12-08
    • 2021-06-28
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多