![](/img/trans.png)
[英]How do I make it so that a user can not post more than one message in a row, discord.js
[英]How can i get value to post as a message in discord.js
我正在尝试创建一个命令,以一条简单的消息输出用户 Xbox gamerscore。 现在我可以使用 Xbox API 检索玩家分数,但我不知道如何将这些数据放入 discord 消息中。
这是我现在的代码:
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 作为 discord 消息发送? 任何帮助将不胜感激欢呼。
这是一个对象数组;
.then((i) => message.reply(i[0].value));
这是假设您在定义message
的事件中。 如:
client.on('message', msg => {
// Code here
});
似乎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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.