javascript - 我怎样才能获得在discord.js中作为消息发布的值(value)

标签 javascript node.js arrays discord.js

我正在尝试创建一个命令,在一条简单的消息中输出用户的 Xbox 玩家分数。现在我可以使用 Xbox API 检索玩家分数,但我不知道如何将该数据放入不和谐消息中。

这是我现在的代码:

        const authInfo = await this._authenticate();
        const userXuid = await XboxLiveAPI.getPlayerXUID(gamertag, authInfo);

        XboxLiveAPI.getPlayerSettings(gamertag, authInfo, ['Gamerscore']).then(console.info);
    }

这是返回到控制台的内容:

2020-07-07T13:29:07.533242+00:00 app[worker.1]: [ { id: 'GamerScore', value: '78855' } ]

结论

那么我如何获取值 78855 作为不和谐消息发送?任何帮助将不胜感激。

最佳答案

看起来 XboxLiveAPI.getPlayerSettings() 是一个异步操作并返回一个 promise 。

你尝试过吗:

const scores = await XboxLiveAPI.getPlayerSettings(gamertag, authInfo, ['Gamerscore']);
const value = scores[0].value;

// the extracted value can now be sent in a discord message.
message.reply(value)

或者使用 .then() 功能,您可以按以下方式更新代码:

XboxLiveAPI.getPlayerSettings(gamertag, authInfo, ['Gamerscore']).then((scores) => message.reply(scores[0].value);

关于javascript - 我怎样才能获得在discord.js中作为消息发布的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62776642/

相关文章:

javascript - 如何创建一个插件来在 Adob​​e CQ 5 的富文本编辑器中添加附件或文件?

javascript - 从文本中提取关键短语(1-4 个词的 ngram)

javascript - 不变违规 : Usage Issue for npm Library

c++ - 将 unsigned char* 数组转换为 std::string

javascript - 在 HTML 文件中使用 Javascript 逐行读取文本文件并存储在变量中

javascript - 全日历日期范围不显示今年过去的事件

javascript - 具有多个数组的 JSON 对象

Node.js apache 基准测试

node.js - 使用 SMTP 的 Firebase 功能可以在模拟器中运行,但在部署时超时

arrays - 内存自适应合并算法?