繁体   English   中英

如何修复此代码以使其能够编译?

[英]How do I fix this code to allow it to compile?

我正在尝试为hubot编写脚本,似乎我有一个未封闭的字符串。 内容将以带有emoji表情符号的html格式显示,例如:smile:等。它不会在Cofeescript中编译。 我是javascript新手,不胜感激。

我得到的错误是

 ERROR Unable to load /var/discourse/avebot/scripts/test: /var/discourse/avebot/scripts/test.js:5
    msg.reply("Hello! I’m Avebot, and I will be your guide throughout your training. :smile: <br>
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
  at new Script (vm.js:51:7)

脚本是:

robot.hear(/hi bot/, function(msg) {

    msg.reply("Hello! I’m a bot, and I will be your guide your training. :smile: <br>

<br>After finishing this training, you will be able to do x y z. :tada:<br>
Are you ready? If so, let me know you are ready by replying 'yes I’m ready!'");

    //Start a dialog with the user that sent this message.
    var dialog = switchBoard.startDialog(msg);

    //Provide choices for the next step, wait for the user.
    dialog.addChoice(/yes/, function(msg2){  msg2.reply('Okay');}

    dialog.addChoice( /no/, function(msg2){    msg2.reply("Okay, I'll wait"); }

    //The dialog will expire after 30 secods.
});

您需要通过在撇号前加一个反斜杠来避免'' I'm Avebot '(因此, I'm Avebot I\\'m Avebot )。

在此处查看站点,以获取有关JS转义序列的更多信息。

为了在Javascript中定义多行字符串,可以在换行之前使用反斜杠\\

msg.reply("Hello! I’m a bot, and I will be your guide your training. :smile: <br>\
<br>After finishing this training, you will be able to do x y z. :tada:<br>\
Are you ready? If so, let me know you are ready by replying 'yes I’m ready!'");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM