You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node Discord Bot股票报价代码语法错误排查问询

Issues & Fixes for Your Discord Bot Stock Quote Code

Hey there, let's walk through the problems in your code that are stopping it from pulling stock symbol, name, and price correctly:

  • Broken arrow function syntax: You've got async () => in your code — that's an HTML escaped character instead of the standard => arrow function syntax. JavaScript won't recognize this, so it's a direct syntax error that breaks the function.
  • Incorrect handling of API response: The Financial Modeling Prep /quote endpoint returns an array of objects (even when you request a single stock like AAPL). Your current code tries to access quoteValue.symbol directly, but quoteValue is an array, not a single object. You need to grab the first element from the array.
  • Redundant variable name (optional clean-up): You declared a function named getQuote inside the command === 'getQuote' block. While this isn't a syntax error, it's confusing to reuse the same name like this — renaming the function to something like fetchStockQuote makes the code clearer.

Fixed Code

if (command === 'getQuote') { 
  const fetchStockQuote = async () => { 
    const response = await axios.get('https://financialmodelingprep.com/api/v3/quote/AAPL?apikey=demo'); 
    // Grab the first (and only) stock object from the response array
    return response.data[0]; 
  }; 

  const quoteValue = await fetchStockQuote(); 
  console.log(quoteValue); 

  message.reply(`Here's your quote:
Symbol: ${quoteValue.symbol}
Name: ${quoteValue.name}
Price: $${quoteValue.price}`); 
}

One quick extra check: Make sure you've properly imported axios at the top of your file (either const axios = require('axios'); for CommonJS or import axios from 'axios'; for ES modules) — without that, you'll get an axios is not defined error.

内容的提问来源于stack exchange,提问作者dilonv2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 20:03:13