node.js - 节点 Discord.js Axios API 索引
问题描述
我想通过存储在 json 文件中的项目列表进行索引,并调用每个 API 并带回数据。下面的代码显示了通过构建 API 链接来工作的索引/映射,但是如何让整个 API 调用和消息在索引内,以便每个列表项都由 API 调用和返回:
// {"342671641006047252":["MSFT","AMZN","CVNA","TEAM"]}
console.log(list);
// This is indexing through the list and bulding the link
const tickers = list
.map((ticker, index) => `https://financialmodelingprep.com/api/v3/quote/${ticker}?apikey=6c7ee1f3c7a666228979fa0678fa22a3`)
return message.channel.send(tickers)
// This is going to the api for list[0]
axios.get('https://financialmodelingprep.com/api/v3/quote/'+list[0]+'?apikey=6c7ee1f3c7a666228979fa0678fa22a3').then(resp => {
console.log(resp.data);
let symbol = resp.data[0].symbol;
let price = resp.data[0].price;
let changesPercentage = resp.data[0].changesPercentage;
return message.channel.send({embed: {
color: 8311585,
fields: [{
name: "Ticker",
value: `${symbol}`,
inline: "true"
},
{
name: "Price",
value: `${price}`,
inline: "true"
},
{
name: "Change %",
value: `${changesPercentage}`,
inline: "true"
},
解决方案
没关系这个!我使用 forEach 而不是 .map 并让它工作!
推荐阅读
- sql - 根据另一列值选择一列中的查询最小值和最大值
- c++ - 为什么 (0 < 5 < 2) 在 C++ 中结果为真?
- android - 根据给定的参数播放不同的音频文件
- python - 从列表中计算条件概率
- python - 是什么让 django 删除斜杠?
- javascript - 如何使用 node.js 通过 SSH 隧道连接到 AWS MSSQL 数据库?
- node.js - MongooseServerSelectionError:在 Windows 7 中连接 ECONNREFUSED 127.0.0.1:27017
- python - 从剧本动态设置 ansible_network_os
- python - 用于为 AutoML Natural Language 创建 JSONL 训练文件的 Python 脚本
- pandas - 迭代保存为多个列表,而不是一个