提问者:小点点

如何在discord.js中获得作为消息发布值


我试图创建一个命令,在一个简单的消息中输出用户的Xbox gamerscore。 现在,我可以使用Xbox API检索gamerscore,但我不知道如何将这些数据输入不一致消息。

这是我现在的代码:

        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应用程序[Worker1]:[{id:'GamerScore',value:'78855'}]

结论

那么,如何获得值78855作为不一致消息发送呢? 任何帮助都将不胜感激。


共2个答案

匿名用户

看起来XBoxLiveAPI.GetPlayerSettings()是一个异步操作,并返回一个承诺。

你试过:

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);

匿名用户

这是一个对象数组;

.then((i) => message.reply(i[0].value);

这是假设您位于定义了message的事件中。 例如:

client.on('message', msg => {
   // Code here
});