为了账号安全,请及时绑定邮箱和手机立即绑定

Discord Roblox 机器人

Discord Roblox 机器人

阿晨1998 2024-01-18 14:54:04
我正在尝试创建一个命令来输出玩家收藏品并总结recentAveragePrice列出的物品总数。问题是当我尝试输出此 API 的任何部分时,它只是输出undefined.API URL: https://inventory.roblox.com/v1/users/1417341214/assets/collectibles ?assetType=Hat&sortOrder=Desc&limit=100if (command === "inv"){    let getInv = async () => {        let response = await axios.get("https://inventory.roblox.com/v1/users/1417341214/assets/collectibles?sortOrder=Asc&limit=100");        let inv = response.data;        return inv;    }    let invValue = await getInv();    console.log(invValue);    message.channel.send(`${invValue.data.name} \n ${invValue.data.recentAveragePrice}`);}
查看完整描述

1 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

这是因为返回的数据是一个对象数组。如果您想将它们全部作为消息发送,您可以迭代它们。如果您想将它们一一发送,可以使用以下方法:


if (command === 'inv') {

  const getInv = async () => {

    const response = await axios.get(

      'https://inventory.roblox.com/v1/users/1417341214/assets/collectibles?sortOrder=Asc&limit=100',

    );

    return response.data;

  };

  const invValue = await getInv();

  let total = 0;

  invValue.data.forEach((item) => {

    message.channel.send(`${item.name} \n ${item.recentAveragePrice}`);

    total += item.recentAveragePrice;

  });

  message.channel.send(`Total average price: ${total}`);

}

结果:

https://img1.sycdn.imooc.com/65a8cb2b0001542004480435.jpg

查看完整回答
反对 回复 2024-01-18
  • 1 回答
  • 0 关注
  • 33 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信