我正在尝试创建一个简单的 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 channel ,但是,上传到我的 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]#
谁能指出可能出现的问题吗?
最佳答案
通过 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
关于javascript - 语法错误: Unexpected Identifier when using discord-webhooks/javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528500/