【问题标题】:I need help accessing info inside an object我需要帮助访问对象内部的信息
【发布时间】:2019-06-04 15:54:40
【问题描述】:

在 Discord 机器人上工作,我需要用户 ID,在本例中为“xxx”。不知道如何获得它。

我试过了 n.mentions.users.User。 -- n.mentions.users.User()

我的应用中有什么:

bot.on('message', msg => {
    if (msg.content === 'myId'){
        msg.reply().then(n => {
            console.log(n.mentions.users);
        });
    }
})

我得到了什么:

Collection [Map] {
  '1803209281398201380913' => User {
    id: 'xxx',
    username: 'zzz',
    discriminator: '0000'
}

我期望 'xxx' 但未定义。

【问题讨论】:

标签: javascript object


【解决方案1】:

使用这个:

message.mentions.users.first().id

【讨论】:

  • msg.reply().then(n => { console.log(message.mentions.users.first()); }); } }) 像这样?
  • 已解决:console.log(n.mentions.users.entries().next().value[1].id);
猜你喜欢
  • 2015-07-16
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-04
相关资源
最近更新 更多