Alexa 技能响应抱歉,我无法按照您的要求进行操作。请再试一遍

Alexa skill responding Sorry, I had trouble doing what you asked. Please try again

const FactIntentHandler = {
        canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return (request.type === 'IntentRequest' && request.intent.name === 'GetFactIntent');
        //&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetFactIntent';
},
handle(handlerInput) {
    var newFact = pitFile.facts[Math.floor(Math.random() * pitFile.fact.length)];//search for fact to return in random order 000561
    var factResult = newFact.text; // store fact 000561
    //speakoutput is a var and not a const because we want it to change 000561
    var speakOutput = "Here's why we love pits:" + factResult;

    return handlerInput.responseBuilder
        .speak(speakOutput)
        //.reprompt(speakOutput)
        .getResponse();
  }
};

这是我的代码,我使用的是 hello world 模板。我编辑了内置的 helloworld 意图,但是当我调用 getfactintent 时,我收到一条错误消息。

你是怎么问的?真实的还是通过技能控制台中的“测试”选项卡?

如果是真的:尝试在技能控制台中做同样的事情并测试你的技能。您将在右侧的 JSON 响应中看到响应,并且可能会看到更详细的错误解释。

如果这是 Alexa 托管技能,请尝试代码面板左下方的 CloudWatch link。如果有错误消息,日志应该包含一条错误消息。

抓取随机事实时,使用的是数组“pitFile.fact”,但在随机数生成中得到的长度是“pitFile.facts”。有人会认为这些应该是一样的。

因为它们不是,你可能会得到一个错误,它“无法读取 属性 未定义的长度”或者 pitFile.fact 不是一个数组。这将显示在 CloudWatch 日志中。

我找到了错误,在第 8 行的代码 var newFact = pitFile.facts[Math.floor(Math.random() * pitFile.fact.length)];//以随机顺序搜索到 return 的事实 000561

"pitFile.fact.length" 实际上应该是 "pitFile.facts.length"