I'm trying to create a command which outputs the users Xbox gamerscore in a simple message. Right now I'm able to retrieve the gamerscore using the Xbox API but I don't know how to get that data into a discord message.
This is my code right now:
const authInfo = await this._authenticate();
const userXuid = await XboxLiveAPI.getPlayerXUID(gamertag, authInfo);
XboxLiveAPI.getPlayerSettings(gamertag, authInfo, ['Gamerscore']).then(console.info);
}
And this is what is returned to the console:
2020-07-07T13:29:07.533242+00:00 app[worker.1]: [ { id: 'GamerScore', value: '78855' } ]
Conclusion
So how would I get the value 78855 to send as a discord message? Any help would be greatly appreciated cheers.
This is an array of objects;
.then((i) => message.reply(i[0].value));
This is assuming you're within an event where message
is defined. Such as:
client.on('message', msg => {
// Code here
});
It seems like XboxLiveAPI.getPlayerSettings()
is an asynchronouse operation and returns a promise.
Have you tried:
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)
Or using the.then() functionality you may update your code in the following way:
XboxLiveAPI.getPlayerSettings(gamertag, authInfo, ['Gamerscore']).then((scores) => message.reply(scores[0].value);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.