我正在尝试创建一个命令,在一条简单的消息中输出用户的 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/