【问题标题】:SyntaxError: Unexpected Identifier when using discord-webhooks / javascriptSyntaxError: Unexpected Identifier when using discord-webhooks / javascript
【发布时间】:2017-05-22 13:29:18
【问题描述】:

我正在尝试创建一个简单的 javascript 作为 Discord 的 webhook。我已删除网址。

const DiscordWebhook = require("discord-webhooks");
let myWebhook = new DiscordWebhook("removedtopostonstackexchange")
myWebhook.on("ready", () => {
myWebhook.execute({
content:"Hello from a webhook",
username:"Mr Webhook",
avatar_url:"https://example.com/image.png"});});
myWebhook.on("error", (error) => {console.warn(error);});

当我在 runkit 中运行它时,它工作正常,并且成功的推送被发送到 Discord 频道,但是,上传到我的 linux 服务器返回以下错误:

[root@pikachu crash-watcher]# node test.js

/servers/crash-watcher/test.js:2
let myWebhook = new DiscordWebhook("removedtopostonstackexchange
    ^^^^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:945:3
[root@pikachu crash-watcher]#

谁能提出可能是什么问题?

【问题讨论】:

    标签: javascript node.js webhooks discord


    【解决方案1】:

    通过node --version检查你的NodeJS版本,它可能已经过时了

    应在 NodeJS 4 中添加对 let 语句的支持


    要升级您的 NodeJS 版本,请运行:

    sudo npm cache clean -f
    sudo npm install n -g
    sudo n stable
    

    旁注:对于 windows 用户,check out this stackoverflow thread

    【讨论】:

      【解决方案2】:

      服务器上安装的nodejs版本不喜欢用let。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-13
        • 2017-10-13
        • 2013-01-15
        • 1970-01-01
        • 1970-01-01
        • 2023-03-30
        • 2019-10-06
        • 1970-01-01
        相关资源
        最近更新 更多